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 f4149e
 (c) 2016-2017 - 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 unittest
Pierre-Yves Chibon 1d1633
import sys
Pierre-Yves Chibon 1d1633
import os
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
import pygit2
Pierre-Yves Chibon 1d1633
from mock import patch
Clement Verna c01836
import pagure.lib
Clement Verna c01836
import tests
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
Clement Verna 109c4b
class PagureFlaskRepoOldUrltests(tests.SimplePagureTest):
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 b130e5
        pagure.config.config['EMAIL_SEND'] = False
Pierre-Yves Chibon b130e5
        pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'releases')
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon b130e5
    @patch.dict('pagure.config.config', {'OLD_VIEW_COMMIT_ENABLED': True})
Lubomír Sedlář a25e58
    def test_view_commit_old_with_bogus_url(self):
Pierre-Yves Chibon d49b8c
        """ Test the view_commit_old endpoint. """
Pierre-Yves Chibon 64afef
Pierre-Yves Chibon d49b8c
        tests.create_projects(self.session)
Pierre-Yves Chibon d49b8c
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon d49b8c
Pierre-Yves Chibon d49b8c
        # Add a README to the git repo - First commit
Pierre-Yves Chibon d49b8c
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Clement Verna c01836
        pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon d49b8c
Pierre-Yves Chibon d49b8c
        # View first commit
Pierre-Yves Chibon d49b8c
        output = self.app.get('/apple-touch-icon-152x152-precomposed.png')
Pierre-Yves Chibon d49b8c
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 1a0280
Pierre-Yves Chibon b130e5
    @patch.dict('pagure.config.config', {'OLD_VIEW_COMMIT_ENABLED': True})
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)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
        # Add a README to the git repo - First commit
Patrick Uiterwijk 170974
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Patrick Uiterwijk 170974
        repo = pygit2.Repository(os.path.join(self.path, 'repos', '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)
Clement Verna b5576a
        self.assertTrue(
Clement Verna b5576a
            '+16' in output.data)
Clement Verna b5576a
        self.assertTrue('title="View file as of %s"' % commit.oid.hex[0:6]
Clement Verna b5576a
                        in output.data)
Pierre-Yves Chibon 1d1633
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
Patrick Uiterwijk 170974
        tests.add_content_git_repo(os.path.join(self.path, 'repos',
Patrick Uiterwijk 170974
                                   'test.git'))
Pierre-Yves Chibon 1d1633
Patrick Uiterwijk 170974
        repo = pygit2.Repository(os.path.join(self.path, 'repos', '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(
Patrick Uiterwijk 170974
            self.path, 'repos', '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)
Clement Verna b5576a
        self.assertTrue(
Clement Verna b5576a
            '+16' in output.data)
Clement Verna b5576a
        self.assertTrue('title="View file as of %s"' % commit.oid.hex[0:6]
Clement Verna b5576a
                        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 393f31
    unittest.main(verbosity=2)