Blame tests/test_zzz_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 64afef
        tests.reload_pagure(CONFIG)
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
Jeremy Cline 20109f
        pagure.APP.config['GIT_FOLDER'] = self.path
Pierre-Yves Chibon 1d1633
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'requests')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'tickets')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'docs')
Pierre-Yves Chibon 1d1633
        pagure.APP.config['UPLOAD_FOLDER_PATH'] = os.path.join(
Jeremy Cline 20109f
            self.path, '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 64afef
Pierre-Yves Chibon 64afef
        tests.reload_pagure(CONFIG)
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)
Jeremy Cline 20109f
        tests.create_projects_git(self.path, bare=True)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Add a README to the git repo - First commit
Jeremy Cline 20109f
        tests.add_readme_git_repo(os.path.join(self.path, 'test.git'))
Jeremy Cline 20109f
        repo = pygit2.Repository(os.path.join(self.path, '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 d73d04
        self.assertTrue('  Merged by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Mark Reynolds 48bfcb
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            '' +
Mark Reynolds 48bfcb
            ' 2 
Mark Reynolds 48bfcb
            '#ddffdd">+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            '' +
Mark Reynolds 48bfcb
            ' 3 
Mark Reynolds 48bfcb
            '#ddffdd">+ ======' 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 d73d04
        self.assertTrue('  Merged by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Mark Reynolds 48bfcb
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            ' 2' +
Mark Reynolds 48bfcb
            ' ' +
Mark Reynolds 48bfcb
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            '' +
Mark Reynolds 48bfcb
            ' 3 
Mark Reynolds 48bfcb
            '#ddffdd">+ ======' in output.data)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Add some content to the git repo
Jeremy Cline 20109f
        tests.add_content_git_repo(os.path.join(self.path, 'test.git'))
Pierre-Yves Chibon 1d1633
Jeremy Cline 20109f
        repo = pygit2.Repository(os.path.join(self.path, '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 8544f4
        self.assertTrue('  Authored by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Pierre-Yves Chibon 1d1633
            # new version of pygments
Mark Reynolds 48bfcb
            '
Mark Reynolds 48bfcb
            '="line-height: 125%">
Mark Reynolds 48bfcb
            ': #f0f0f0; padding: 0 5px 0 5px">1 
Mark Reynolds 48bfcb
            '#800080; font-weight: bold">@@ -0,0 +1,3 @@' in
Mark Reynolds 48bfcb
            output.data
Pierre-Yves Chibon 1d1633
            or
Pierre-Yves Chibon 1d1633
            # old version of pygments
Mark Reynolds 48bfcb
            '
' +
Mark Reynolds 48bfcb
            '
' +
Mark Reynolds 48bfcb
            '' +
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',
farhaanbukhsh 907098
            is_fork=True,
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(
Jeremy Cline 20109f
            self.path, '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 8544f4
        self.assertTrue('  Authored by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            ' 2' +
Mark Reynolds 48bfcb
            ' ' +
Mark Reynolds 48bfcb
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            ' 3' +
Mark Reynolds 48bfcb
            ' ' +
Mark Reynolds 48bfcb
            '+ ======' 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 8544f4
        self.assertTrue('  Authored by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            ' 2' +
Mark Reynolds 48bfcb
            ' ' +
Mark Reynolds 48bfcb
            '+ Pagure' in output.data)
Pierre-Yves Chibon 1d1633
        self.assertTrue(
Mark Reynolds 48bfcb
            ' 3' +
Mark Reynolds 48bfcb
            ' ' +
Mark Reynolds 48bfcb
            '+ ======' 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)