Blame tests/test_pagure_flask_ui_old_commit.py

Pierre-Yves Chibon 1d1633
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
"""
Pierre-Yves Chibon 1d1633
 (c) 2016 - Copyright Red Hat Inc
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
 Authors:
Pierre-Yves Chibon 1d1633
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
"""
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 1d1633
import pkg_resources
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
import datetime
Pierre-Yves Chibon 1d1633
import json
Pierre-Yves Chibon 1d1633
import unittest
Pierre-Yves Chibon 1d1633
import shutil
Pierre-Yves Chibon 1d1633
import sys
Pierre-Yves Chibon 1d1633
import tempfile
Pierre-Yves Chibon 1d1633
import os
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
import pygit2
Pierre-Yves Chibon 1d1633
from mock import patch
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 1d1633
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
HERE = os.path.join(os.path.dirname(os.path.abspath(__file__)))
Pierre-Yves Chibon 1d1633
CONFIG = os.path.join(HERE, 'test_config')
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
os.environ['PAGURE_CONFIG'] = CONFIG
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
import pagure.lib
Pierre-Yves Chibon 1d1633
import tests
Pierre-Yves Chibon 1d1633
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
class PagureFlaskRepoOldUrltests(tests.Modeltests):
Pierre-Yves Chibon 1d1633
    """ Tests for flask app controller of pagure """
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
    def setUp(self):
Pierre-Yves Chibon 1d1633
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 1d1633
        super(PagureFlaskRepoOldUrltests, self).setUp()
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1a0280
        # We need to reload pagure as otherwise the configuration file will
Pierre-Yves Chibon 1a0280
        # not be taken into account
Pierre-Yves Chibon 1a0280
        pagure.APP.view_functions = {}
Pierre-Yves Chibon 1a0280
        os.environ['PAGURE_CONFIG'] = CONFIG
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon 1a0280
        reload(pagure)
Pierre-Yves Chibon 1a0280
        reload(pagure.lib)
Pierre-Yves Chibon 1a0280
        reload(pagure.lib.model)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.admin)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.app)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.groups)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.repo)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.filters)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.issues)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.fork)
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon 1d1633
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon 1d1633
        pagure.SESSION = self.session
Pierre-Yves Chibon 1d1633
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon 1d1633
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon 1d1633
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon 1d1633
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        pagure.APP.config['OLD_VIEW_COMMIT_ENABLED'] = True
Pierre-Yves Chibon 1a0280
        pagure.APP.config['EMAIL_SEND'] = False
Pierre-Yves Chibon 1d1633
        pagure.APP.config['GIT_FOLDER'] = tests.HERE
Pierre-Yves Chibon 1d1633
        pagure.APP.config['FORK_FOLDER'] = os.path.join(
Pierre-Yves Chibon 1d1633
            tests.HERE, 'forks')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 1d1633
            tests.HERE, 'requests')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 1d1633
            tests.HERE, 'tickets')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 1d1633
            tests.HERE, 'docs')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['UPLOAD_FOLDER_PATH'] = os.path.join(
Pierre-Yves Chibon 1d1633
            tests.HERE, 'releases')
Pierre-Yves Chibon 1d1633
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1a0280
    def tearDown(self):
Pierre-Yves Chibon 1a0280
        """ Tear down the environnment, after every tests. """
Pierre-Yves Chibon 1a0280
        super(PagureFlaskRepoOldUrltests, self).tearDown()
Pierre-Yves Chibon 1a0280
        if 'PAGURE_CONFIG' in os.environ:
Pierre-Yves Chibon 1a0280
            del os.environ['PAGURE_CONFIG']
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon 1a0280
        # We need to reload pagure as otherwise the configuration file will
Pierre-Yves Chibon 1a0280
        # remain set for the other tests
Pierre-Yves Chibon 1a0280
        pagure.APP.view_functions = {}
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon 1a0280
        reload(pagure)
Pierre-Yves Chibon 1a0280
        reload(pagure.lib)
Pierre-Yves Chibon 1a0280
        reload(pagure.lib.model)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.mail)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.irc)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.fedmsg)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.pagure_force_commit)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.pagure_hook)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.pagure_request_hook)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.pagure_ticket_hook)
Pierre-Yves Chibon 1a0280
        reload(pagure.hooks.rtd)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.admin)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.app)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.groups)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.repo)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.filters)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.plugins)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.issues)
Pierre-Yves Chibon 1a0280
        reload(pagure.ui.fork)
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon 1a0280
        pagure.APP.config['EMAIL_SEND'] = False
Pierre-Yves Chibon 1a0280
        pagure.LOG.handlers = []
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon 1d1633
    def test_view_commit_old(self):
Pierre-Yves Chibon 1d1633
        """ Test the view_commit_old endpoint. """
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        tests.create_projects(self.session)
Pierre-Yves Chibon 1d1633
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Add a README to the git repo - First commit
Pierre-Yves Chibon 1d1633
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 1d1633
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 1d1633
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # View first commit
Pierre-Yves Chibon 1d1633
        output = self.app.get('/test/%s' % commit.oid.hex)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/test/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(' Authored by Alice Author' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue('Committed by Cecil Committer' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ ======' in output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon 1d1633
        # View first commit - with the old URL scheme
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/test/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(' Authored by Alice Author' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue('Committed by Cecil Committer' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ ======' in output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Add some content to the git repo
Pierre-Yves Chibon 1d1633
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 1d1633
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # View another commit
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/test/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(' Authored by Alice Author' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue('Committed by Cecil Committer' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            # new version of pygments
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            ''
Pierre-Yves Chibon 1d1633
            ''
Pierre-Yves Chibon 1d1633
            '@@ -0,0 +1,3 @@' in output.data
Pierre-Yves Chibon 1d1633
            or
Pierre-Yves Chibon 1d1633
            # old version of pygments
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            ''
Pierre-Yves Chibon 1d1633
            '@@ -0,0 +1,3 @@' in output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Add a fork of a fork
Pierre-Yves Chibon 1d1633
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 1d1633
            user_id=1,  # pingou
Pierre-Yves Chibon 1d1633
            name='test3',
Pierre-Yves Chibon 1d1633
            description='test project #3',
Pierre-Yves Chibon 1d1633
            parent_id=1,
Pierre-Yves Chibon 1d1633
            hook_token='aaabbbkkk',
Pierre-Yves Chibon 1d1633
        )
Pierre-Yves Chibon 1d1633
        self.session.add(item)
Pierre-Yves Chibon 1d1633
        self.session.commit()
Pierre-Yves Chibon 1d1633
        forkedgit = os.path.join(
Pierre-Yves Chibon 1d1633
            tests.HERE, 'forks', 'pingou', 'test3.git')
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        tests.add_content_git_repo(forkedgit)
Pierre-Yves Chibon 1d1633
        tests.add_readme_git_repo(forkedgit)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        repo = pygit2.Repository(forkedgit)
Pierre-Yves Chibon 1d1633
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Commit does not exist in anothe repo :)
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/test/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # View commit of fork
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/fork/pingou/test3/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(' Authored by Alice Author' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue('Committed by Cecil Committer' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ ======' in output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # View commit of fork - With the old URL scheme
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/fork/pingou/test3/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '
'
Pierre-Yves Chibon 1d1633
            in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(' Authored by Alice Author' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue('Committed by Cecil Committer' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            '+ ======' in output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Try the old URL scheme with a short hash
Pierre-Yves Chibon 1d1633
        output = self.app.get(
Pierre-Yves Chibon 1d1633
            '/fork/pingou/test3/%s' % commit.oid.hex[:10],
Pierre-Yves Chibon 1d1633
            follow_redirects=True)
Pierre-Yves Chibon 1d1633
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 1d1633
        self.assertIn('

Project not found

', output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
if __name__ == '__main__':
Pierre-Yves Chibon 1d1633
    SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskRepoOldUrltests)
Pierre-Yves Chibon 1d1633
    unittest.TextTestRunner(verbosity=2).run(SUITE)