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 9071b6
 (c) 2016-2018 - 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 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
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
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 930073
import pagure.lib.query
Pierre-Yves Chibon 930073
import tests
Pierre-Yves Chibon 930073
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(
Ryan Lerch e2f045
            'href="#commit-overview-collapse"'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Merged by Alice Author' in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
Mark Reynolds 48bfcb
Clement Verna b5576a
        self.assertTrue('title="View file as of %s"' % commit.oid.hex[0:6]
Aurélien Bompard 626417
                        in output.get_data(as_text=True))
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(
Ryan Lerch e2f045
            'href="#commit-overview-collapse"'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Merged by Alice Author' in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
Mark Reynolds 48bfcb
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(
Ryan Lerch e2f045
            'href="#commit-overview-collapse"'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Authored by Alice Author' in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
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(
Ryan Lerch e2f045
            'href="#commit-overview-collapse"'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Aurélien Bompard 626417
        self.assertTrue('  Authored by Alice Author\n' in output.get_data(as_text=True))
Aurélien Bompard 626417
        self.assertTrue('  Committed by Cecil Committer\n' in output.get_data(as_text=True))
Ryan Lerch e2f045
Clement Verna b5576a
        self.assertTrue('title="View file as of %s"' % commit.oid.hex[0:6]
Aurélien Bompard 626417
                        in output.get_data(as_text=True))
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(
Ryan Lerch e2f045
            'href="#commit-overview-collapse"'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Authored by Alice Author' in output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
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)
Aurélien Bompard 626417
        self.assertIn('

Project not found

', output.get_data(as_text=True))
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
Pierre-Yves Chibon 1d1633
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)