# -*- coding: utf-8 -*- """ (c) 2016-2017 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon """ __requires__ = ['SQLAlchemy >= 0.8'] import unittest import sys import os import pygit2 from mock import patch import pagure.lib import tests sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) class PagureFlaskRepoOldUrltests(tests.SimplePagureTest): """ Tests for flask app controller of pagure """ def setUp(self): """ Set up the environnment, ran before every tests. """ super(PagureFlaskRepoOldUrltests, self).setUp() pagure.config.config['EMAIL_SEND'] = False pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join( self.path, 'releases') @patch.dict('pagure.config.config', {'OLD_VIEW_COMMIT_ENABLED': True}) def test_view_commit_old_with_bogus_url(self): """ Test the view_commit_old endpoint. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) # Add a README to the git repo - First commit tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) # View first commit output = self.app.get('/apple-touch-icon-152x152-precomposed.png') self.assertEqual(output.status_code, 404) @patch.dict('pagure.config.config', {'OLD_VIEW_COMMIT_ENABLED': True}) def test_view_commit_old(self): """ Test the view_commit_old endpoint. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) # Add a README to the git repo - First commit tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) commit = repo.revparse_single('HEAD') # View first commit output = self.app.get('/test/%s' % commit.oid.hex) self.assertEqual(output.status_code, 302) output = self.app.get( '/test/%s' % commit.oid.hex, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertTrue( '