# -*- coding: utf-8 -*- """ (c) 2015-2017 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon """ __requires__ = ['SQLAlchemy >= 0.8'] import pkg_resources import datetime import json import unittest import re import shutil import sys import tempfile import time import os import pygit2 from mock import ANY, patch, MagicMock sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) import pagure import pagure.lib import tests from pagure.lib.repo import PagureRepo class PagureFlaskRepotests(tests.Modeltests): """ Tests for flask app controller of pagure """ def setUp(self): """ Set up the environnment, ran before every tests. """ super(PagureFlaskRepotests, self).setUp() pagure.config.config['VIRUS_SCAN_ATTACHMENTS'] = False pagure.config.config['UPLOAD_FOLDER_URL'] = '/releases/' pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join( self.path, 'releases') @patch('pagure.decorators.admin_session_timedout') def test_add_user_when_user_mngt_off(self, ast): """ Test the add_user endpoint when user management is turned off in the pagure instance """ pagure.config.config['ENABLE_USER_MNGT'] = False ast.return_value = False # No Git repo output = self.app.get('/foo/adduser') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # User not logged in output = self.app.get('/test/adduser') self.assertEqual(output.status_code, 302) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/test/adduser') self.assertEqual(output.status_code, 404) #just get the csrf token pagure.config.config['ENABLE_USER_MNGT'] = True output = self.app.get('/test/adduser') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] pagure.config.config['ENABLE_USER_MNGT'] = False data = { 'user': 'ralph', } output = self.app.post('/test/adduser', data=data) self.assertEqual(output.status_code, 404) data['csrf_token'] = csrf_token output = self.app.post('/test/adduser', data=data) self.assertEqual(output.status_code, 404) data['user'] = 'foo' tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.post( '/test/adduser', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) pagure.config.config['ENABLE_USER_MNGT'] = True @patch('pagure.decorators.admin_session_timedout') def test_add_deploykey(self, ast): """ Test the add_deploykey endpoint. """ ast.return_value = False # No git repo output = self.app.get('/foo/adddeploykey') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # User not logged in output = self.app.get('/test/adddeploykey') self.assertEqual(output.status_code, 302) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.get('/test/adddeploykey') self.assertEqual(output.status_code, 403) ast.return_value = True output = self.app.get('/test/adddeploykey') self.assertEqual(output.status_code, 302) # Redirect also happens for POST request output = self.app.post('/test/adddeploykey') self.assertEqual(output.status_code, 302) # Need to do this un-authentified since our fake user isn't in the DB # Check the message flashed during the redirect output = self.app.get('/') self.assertEqual(output.status_code, 200) self.assertIn( '\n Action canceled, try it ' 'again',output.data) ast.return_value = False user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.get('/test/adddeploykey') self.assertEqual(output.status_code, 200) self.assertIn('Add deploy key to the', output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = { 'ssh_key': 'asdf', 'pushaccess': 'false' } # No CSRF token output = self.app.post('/test/adddeploykey', data=data) self.assertEqual(output.status_code, 200) self.assertTrue('Add deploy key to the' in output.data) data['csrf_token'] = csrf_token # First, invalid SSH key output = self.app.post('/test/adddeploykey', data=data) self.assertEqual(output.status_code, 200) self.assertIn('Add deploy key to the', output.data) self.assertIn('Deploy key invalid', output.data) # Next up, multiple SSH keys data['ssh_key'] = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==' output = self.app.post( '/test/adddeploykey', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn('Deploy key can only be single keys.', output.data) # Now, a valid SSH key data['ssh_key'] = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==' output = self.app.post( '/test/adddeploykey', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn('Deploy key added', output.data) self.assertNotIn('PUSH ACCESS', output.data) # And now, adding the same key output = self.app.post( '/test/adddeploykey', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn('Deploy key already exists', output.data) # And next, a key with push access data['ssh_key'] = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9Xwc2RDzPBhlEDARfHldGjudIVoa04tqT1JVKGQmyllTFz7Rb8CngQL3e7zyNzotnhwYKHdoiLlPkVEiDee4dWMUe48ilqId+FJZQGhyv8fu4BoFdE1AJUVylzmltbLg14VqG5gjTpXgtlrEva9arKwBMHJjRYc8ScaSn3OgyQw==' data['pushaccess'] = 'true' output = self.app.post( '/test/adddeploykey', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn('Deploy key added', output.data) self.assertIn('PUSH ACCESS', output.data) @patch('pagure.decorators.admin_session_timedout') @patch.dict('pagure.config.config', {'DEPLOY_KEY': False}) def test_add_deploykey_disabled(self, ast): """ Test the add_deploykey endpoint when it's disabled in the config. """ ast.return_value = False tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/test/adddeploykey') self.assertEqual(output.status_code, 404) output = self.app.post('/test/adddeploykey') self.assertEqual(output.status_code, 404) @patch('pagure.decorators.admin_session_timedout') @patch('pagure.lib.notify.log') def test_add_user(self, mock_log, ast): """ Test the add_user endpoint. """ ast.return_value = False # No git repo output = self.app.get('/foo/adduser') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # User not logged in output = self.app.get('/test/adduser') self.assertEqual(output.status_code, 302) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.get('/test/adduser') self.assertEqual(output.status_code, 403) ast.return_value = True output = self.app.get('/test/adduser') self.assertEqual(output.status_code, 302) # Redirect also happens for POST request output = self.app.post('/test/adduser') self.assertEqual(output.status_code, 302) # Need to do this un-authentified since our fake user isn't in the DB # Check the message flashed during the redirect output = self.app.get('/') self.assertEqual(output.status_code, 200) self.assertIn( '\n Action canceled, try it ' 'again',output.data) ast.return_value = False user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.get('/test/adduser') self.assertEqual(output.status_code, 200) self.assertIn('Add user to the', output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = { 'user': 'ralph', } # Missing access and no CSRF output = self.app.post('/test/adduser', data=data) self.assertEqual(output.status_code, 200) self.assertIn( 'Add user - test - Pagure', output.data) self.assertTrue('Add user to the' in output.data) # No CSRF output = self.app.post('/test/adduser', data=data) self.assertEqual(output.status_code, 200) self.assertIn( 'Add user - test - Pagure', output.data) # Missing access data['csrf_token'] = csrf_token output = self.app.post('/test/adduser', data=data) self.assertEqual(output.status_code, 200) self.assertIn( 'Add user - test - Pagure', output.data) self.assertIn('Add user to the', output.data) # Unknown user data['access'] = 'commit' output = self.app.post('/test/adduser', data=data) self.assertEqual(output.status_code, 200) self.assertIn( 'Add user - test - Pagure', output.data) self.assertIn('Add user to the', output.data) self.assertIn( '\n No user "ralph" found\n', output.data) # All correct data['user'] = 'foo' output = self.app.post( '/test/adduser', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n User added', output.data) mock_log.assert_called_with(ANY, topic='project.user.added', msg=ANY, redis=ANY) @patch('pagure.decorators.admin_session_timedout') def test_add_group_project_when_user_mngt_off(self, ast): """ Test the add_group_project endpoint when user management is turned off in the pagure instance""" pagure.config.config['ENABLE_USER_MNGT'] = False ast.return_value = False # No Git repo output = self.app.get('/foo/addgroup') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # User not logged in output = self.app.get('/test/addgroup') self.assertEqual(output.status_code, 302) msg = pagure.lib.add_group( self.session, group_name='foo', group_type='bar', display_name='foo group', description=None, user='pingou', is_admin=False, blacklist=pagure.config.config['BLACKLISTED_GROUPS'], ) self.session.commit() self.assertEqual(msg, 'User `pingou` added to the group `foo`.') user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): #just get the csrf token pagure.config.config['ENABLE_USER_MNGT'] = True output = self.app.get('/test/addgroup') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] pagure.config.config['ENABLE_USER_MNGT'] = False data = { 'group': 'ralph', } output = self.app.post('/test/addgroup', data=data) self.assertEqual(output.status_code, 404) data['csrf_token'] = csrf_token output = self.app.post('/test/addgroup', data=data) self.assertEqual(output.status_code, 404) data['group'] = 'foo' output = self.app.post( '/test/addgroup', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) pagure.config.config['ENABLE_USER_MNGT'] = True @patch.dict('pagure.config.config', {'ENABLE_GROUP_MNGT': False}) @patch('pagure.decorators.admin_session_timedout') def test_add_group_project_grp_mngt_off(self, ast): """ Test the add_group_project endpoint when group management is turned off in the pagure instance""" ast.return_value = False tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): data = { 'group': 'ralph', 'access': 'ticket', 'csrf_token': self.get_csrf(), } output = self.app.post( '/test/addgroup', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( u'Add group - test - Pagure', output.data) self.assertIn(u'No group ralph found.', output.data) @patch('pagure.decorators.admin_session_timedout') def test_add_group_project(self, ast): """ Test the add_group_project endpoint. """ ast.return_value = False # No Git repo output = self.app.get('/foo/addgroup') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # User not logged in output = self.app.get('/test/addgroup') self.assertEqual(output.status_code, 302) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.get('/test/addgroup') self.assertEqual(output.status_code, 403) ast.return_value = True output = self.app.get('/test/addgroup') self.assertEqual(output.status_code, 302) # Redirect also happens for POST request output = self.app.post('/test/addgroup') self.assertEqual(output.status_code, 302) # Need to do this un-authentified since our fake user isn't in the DB # Check the message flashed during the redirect output = self.app.get('/') self.assertEqual(output.status_code, 200) self.assertIn( '\n Action canceled, try it ' 'again', output.data) ast.return_value = False msg = pagure.lib.add_group( self.session, group_name='foo', display_name='foo group', description=None, group_type='bar', user='pingou', is_admin=False, blacklist=pagure.config.config['BLACKLISTED_GROUPS'], ) self.session.commit() self.assertEqual(msg, 'User `pingou` added to the group `foo`.') user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.get('/test/addgroup') self.assertEqual(output.status_code, 200) self.assertTrue('Add group to the' in output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = { 'group': 'ralph', } # Missing CSRF output = self.app.post('/test/addgroup', data=data) self.assertEqual(output.status_code, 200) self.assertIn( 'Add group - test - Pagure', output.data) self.assertIn('Add group to the', output.data) # Missing access data['csrf_token'] = csrf_token output = self.app.post('/test/addgroup', data=data) self.assertEqual(output.status_code, 200) self.assertIn( 'Add group - test - Pagure', output.data) self.assertIn('Add group to the', output.data) # All good data['access'] = 'ticket' output = self.app.post( '/test/addgroup', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n Group added', output.data) @patch('pagure.decorators.admin_session_timedout') def test_remove_user_when_user_mngt_off(self, ast): """ Test the remove_user endpoint when user management is turned off in the pagure instance""" pagure.config.config['ENABLE_USER_MNGT'] = False ast.return_value = False # Git repo not found output = self.app.post('/foo/dropuser/1') self.assertEqual(output.status_code, 404) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.post('/test/settings') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropuser/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) # User not logged in output = self.app.post('/test/dropuser/1') self.assertEqual(output.status_code, 302) # Add an user to a project repo = pagure.lib.get_authorized_project(self.session, 'test') msg = pagure.lib.add_user_to_project( session=self.session, project=repo, new_user='foo', user='pingou', ) self.session.commit() self.assertEqual(msg, 'User added') with tests.user_set(self.app.application, user): output = self.app.post('/test/dropuser/2', follow_redirects=True) self.assertEqual(output.status_code, 404) data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropuser/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) pagure.config.config['ENABLE_USER_MNGT'] = True @patch('pagure.decorators.admin_session_timedout') def test_remove_deploykey(self, ast): """ Test the remove_deploykey endpoint. """ ast.return_value = False # Git repo not found output = self.app.post('/foo/dropdeploykey/1') self.assertEqual(output.status_code, 404) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.post('/foo/dropdeploykey/1') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.post('/test/dropdeploykey/1') self.assertEqual(output.status_code, 403) ast.return_value = True output = self.app.post('/test/dropdeploykey/1') self.assertEqual(output.status_code, 302) ast.return_value = False # User not logged in output = self.app.post('/test/dropdeploykey/1') self.assertEqual(output.status_code, 302) user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.post('/test/settings') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropdeploykey/1', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn('Deploy key does not exist in project', output.data) # Add a deploy key to a project repo = pagure.lib.get_authorized_project(self.session, 'test') msg = pagure.lib.add_deploykey_to_project( session=self.session, project=repo, ssh_key='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==', pushaccess=True, user='pingou', ) self.session.commit() self.assertEqual(msg, 'Deploy key added') with tests.user_set(self.app.application, user): output = self.app.post('/test/dropdeploykey/1', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertNotIn('Deploy key removed', output.data) data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropdeploykey/1', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn('Deploy key removed', output.data) @patch('pagure.decorators.admin_session_timedout') @patch.dict('pagure.config.config', {'DEPLOY_KEY': False}) def test_remove_deploykey_disabled(self, ast): """ Test the remove_deploykey endpoint when it's disabled in the config. """ ast.return_value = False tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.post('/test/dropdeploykey/1') self.assertEqual(output.status_code, 404) @patch('pagure.decorators.admin_session_timedout') @patch('pagure.lib.notify.log') def test_remove_user(self, mock_log, ast): """ Test the remove_user endpoint. """ ast.return_value = False # Git repo not found output = self.app.post('/foo/dropuser/1') self.assertEqual(output.status_code, 404) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.post('/foo/dropuser/1') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.post('/test/dropuser/1') self.assertEqual(output.status_code, 403) ast.return_value = True output = self.app.post('/test/dropuser/1') self.assertEqual(output.status_code, 302) ast.return_value = False # User not logged in output = self.app.post('/test/dropuser/1') self.assertEqual(output.status_code, 302) user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.post('/test/settings') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropuser/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n User does not have any ' 'access on the repo', output.data) # Add an user to a project repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.users), 0) msg = pagure.lib.add_user_to_project( session=self.session, project=repo, new_user='foo', user='pingou', ) self.session.commit() self.assertEqual(msg, 'User added') self.assertEqual(len(repo.users), 1) with tests.user_set(self.app.application, user): output = self.app.post('/test/dropuser/2', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertNotIn( '\n User removed', output.data) self.assertIn('action="/test/dropuser/2">', output.data) repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.users), 1) data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropuser/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n User removed', output.data) self.assertNotIn('action="/test/dropuser/2">', output.data) self.session.commit() repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.users), 0) mock_log.assert_called_with(ANY, topic='project.user.removed', msg=ANY) @patch('pagure.decorators.admin_session_timedout') @patch('pagure.lib.notify.log') def test_remove_user_self(self, mock_log, ast): """ Test the remove_user endpoint when removing themselves. """ ast.return_value = False tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # Add an user to a project repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.users), 0) msg = pagure.lib.add_user_to_project( session=self.session, project=repo, new_user='foo', user='pingou', ) self.session.commit() self.assertEqual(msg, 'User added') self.assertEqual(len(repo.users), 1) # Let user foo remove themselves user = tests.FakeUser(username='foo') with tests.user_set(self.app.application, user): csrf_token = self.get_csrf() data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropuser/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( u'Overview - test - Pagure', output.data) self.assertIn( u'

\ntest', output.data) self.assertIn( u'\n User removed', output.data) self.session.commit() repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.users), 0) mock_log.assert_called_with(ANY, topic='project.user.removed', msg=ANY) @patch('pagure.decorators.admin_session_timedout') def test_remove_group_project_when_user_mngt_off(self, ast): """ Test the remove_group_project endpoint when user management is turned off in the pagure instance""" pagure.config.config['ENABLE_USER_MNGT'] = False ast.return_value = False # No Git repo output = self.app.post('/foo/dropgroup/1') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # User not logged in output = self.app.post('/test/dropgroup/1') self.assertEqual(output.status_code, 302) user = tests.FakeUser() user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.post('/test/settings') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropgroup/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) # Create the new group msg = pagure.lib.add_group( session=self.session, group_name='testgrp', group_type='user', display_name='testgrp group', description=None, user='pingou', is_admin=False, blacklist=[], ) self.assertEqual(msg, 'User `pingou` added to the group `testgrp`.') self.session.commit() repo = pagure.lib.get_authorized_project(self.session, 'test') # Add the group to a project msg = pagure.lib.add_group_to_project( session=self.session, project=repo, new_group='testgrp', user='pingou', ) self.session.commit() self.assertEqual(msg, 'Group added') with tests.user_set(self.app.application, user): output = self.app.post('/test/dropgroup/1', follow_redirects=True) self.assertEqual(output.status_code, 404) data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropgroup/1', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) pagure.config.config['ENABLE_USER_MNGT'] = True @patch('pagure.decorators.admin_session_timedout') def test_remove_group_project(self, ast): """ Test the remove_group_project endpoint. """ ast.return_value = False # No Git repo output = self.app.post('/foo/dropgroup/1') self.assertEqual(output.status_code, 404) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.post('/foo/dropgroup/1') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.post('/test/dropgroup/1') self.assertEqual(output.status_code, 403) ast.return_value = True output = self.app.post('/test/dropgroup/1') self.assertEqual(output.status_code, 302) ast.return_value = False # User not logged in output = self.app.post('/test/dropgroup/1') self.assertEqual(output.status_code, 302) user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.post('/test/settings') csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropgroup/2', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n ' 'Group does not seem to be part of this project', output.data) # Create the new group msg = pagure.lib.add_group( session=self.session, group_name='testgrp', group_type='user', display_name='testgrp group', description=None, user='pingou', is_admin=False, blacklist=[], ) self.assertEqual(msg, 'User `pingou` added to the group `testgrp`.') self.session.commit() repo = pagure.lib.get_authorized_project(self.session, 'test') # Add the group to a project msg = pagure.lib.add_group_to_project( session=self.session, project=repo, new_group='testgrp', user='pingou', ) self.session.commit() self.assertEqual(msg, 'Group added') repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.groups), 1) with tests.user_set(self.app.application, user): output = self.app.post('/test/dropgroup/1', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn('action="/test/dropgroup/1">', output.data) self.assertNotIn( '\n Group removed', output.data) repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.groups), 1) data = {'csrf_token': csrf_token} output = self.app.post( '/test/dropgroup/1', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n Group removed', output.data) self.assertNotIn('action="/test/dropgroup/1">', output.data) self.session.commit() repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(len(repo.groups), 0) @patch('pagure.decorators.admin_session_timedout') def test_update_project(self, ast): """ Test the update_project endpoint. """ ast.return_value = True # Git repo not found output = self.app.post('/foo/update') self.assertEqual(output.status_code, 404) user = tests.FakeUser() with tests.user_set(self.app.application, user): # Project does not exist output = self.app.post('/foo/update') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) # Session timed-out output = self.app.post('/test/update') self.assertEqual(output.status_code, 302) ast.return_value = False # Not allowed output = self.app.post('/test/update') self.assertEqual(output.status_code, 403) # User not logged in output = self.app.post('/test/update') self.assertEqual(output.status_code, 302) user.username = 'pingou' with tests.user_set(self.app.application, user): output = self.app.post('/test/update', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = { 'description': 'new description for test project #1', 'csrf_token': csrf_token, } output = self.app.post( '/test/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '\n Project updated', output.data) # Edit the avatar_email data = { 'description': 'new description for test project #1', 'avatar_email': 'pingou@fp.o', 'csrf_token': csrf_token, } output = self.app.post( '/test/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '\n Project updated', output.data) # Reset the avatar_email data = { 'description': 'new description for test project #1', 'avatar_email': '', 'csrf_token': csrf_token, } output = self.app.post( '/test/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '\n Project updated', output.data) @patch('pagure.decorators.admin_session_timedout') def test_update_project_update_tag(self, ast): """ Test the view_settings endpoint when updating the project's tags. We had an issue where when you add an existing tag to a project we were querying the wrong table in the database. It would thus not find the tag, would try to add it, and (rightfully) complain about duplicated content. This test ensure we are behaving properly. """ ast.return_value = False tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/test/settings') self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] # Add tag to a project so that they are added to the database data = { 'csrf_token': csrf_token, 'description': 'Test project', 'tags': 'test,pagure,tag', } output = self.app.post( '/test/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n Project updated', output.data) # Remove two of the tags of the project, they will still be in # the DB but not associated to this project data = { 'csrf_token': csrf_token, 'description': 'Test project', 'tags': 'tag', } output = self.app.post( '/test/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n Project updated', output.data) # Try re-adding the two tags, this used to fail before we fixed # it data = { 'csrf_token': csrf_token, 'description': 'Test project', 'tags': 'test,pagure,tag', } output = self.app.post( '/test/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '\n Project updated', output.data) @patch('pagure.decorators.admin_session_timedout') def test_view_settings(self, ast): """ Test the view_settings endpoint. """ ast.return_value = False # No Git repo output = self.app.get('/foo/settings') self.assertEqual(output.status_code, 404) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.get('/foo/settings') self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.get('/test/settings') self.assertEqual(output.status_code, 403) # User not logged in output = self.app.get('/test/settings') self.assertEqual(output.status_code, 302) user.username = 'pingou' with tests.user_set(self.app.application, user): ast.return_value = True output = self.app.get('/test/settings') self.assertEqual(output.status_code, 302) ast.return_value = False output = self.app.get('/test/settings') self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) # Both checkbox checked before self.assertIn( '', output.data) self.assertIn( '', output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = {} output = self.app.post( '/test/settings', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) # Both checkbox are still checked output = self.app.get('/test/settings', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) data = {'csrf_token': csrf_token} output = self.app.post( '/test/settings', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Overview - test - Pagure', output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertIn( '\n Edited successfully ' 'settings of repo: test', output.data) # Both checkbox are now un-checked output = self.app.get('/test/settings', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) data = { 'csrf_token': csrf_token, 'pull_requests': 'y', 'issue_tracker': 'y', } output = self.app.post( '/test/settings', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Overview - test - Pagure', output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertIn( '\n Edited successfully ' 'settings of repo: test', output.data) # Both checkbox are again checked output = self.app.get('/test/settings', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) @patch('pagure.lib.git.generate_gitolite_acls') @patch('pagure.decorators.admin_session_timedout') def test_view_settings_pr_only(self, ast, gen_acl): """ Test the view_settings endpoint when turning on PR only. """ ast.return_value = False tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/test/settings') self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) csrf_token = self.get_csrf(output=output) data = { 'csrf_token': csrf_token, 'pull_requests': 'y', 'issue_tracker': 'y', 'pull_request_access_only': 'y', } output = self.app.post( '/test/settings', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Overview - test - Pagure', output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertIn( '\n Edited successfully ' 'settings of repo: test', output.data) # Both checkbox are again checked output = self.app.get('/test/settings', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) repo = pagure.lib.get_authorized_project(self.session, 'test') self.assertEqual(gen_acl.call_count, 1) args = gen_acl.call_args self.assertEqual(args[0], tuple()) self.assertEqual(args[1].keys(), ['project']) self.assertEqual(args[1]['project'].fullname, 'test') @patch('pagure.decorators.admin_session_timedout') def test_fields_in_view_settings(self, ast): """ Test the default fields in view_settings endpoint. """ ast.return_value = False # No Git repo output = self.app.get('/foo/settings') self.assertEqual(output.status_code, 404) user = tests.FakeUser() with tests.user_set(self.app.application, user): output = self.app.get('/foo/settings') self.assertEqual(output.status_code, 404) item = pagure.lib.model.Project( user_id=1, # pingou name='test', description='test project #1', hook_token='aaabbbccc', ) self.session.add(item) self.session.commit() tests.create_projects_git(os.path.join(self.path, 'repos')) output = self.app.get('/test/settings') self.assertEqual(output.status_code, 403) # User not logged in output = self.app.get('/test/settings') self.assertEqual(output.status_code, 302) user.username = 'pingou' with tests.user_set(self.app.application, user): ast.return_value = True output = self.app.get('/test/settings') self.assertEqual(output.status_code, 302) ast.return_value = False output = self.app.get('/test/settings') self.assertEqual(output.status_code, 200) self.assertIn( 'Settings - test - Pagure', output.data) self.assertIn('

Settings for test

', output.data) # Check that the priorities have their empty fields self.assertIn( '''
''', output.data) # Check that the milestones have their empty fields self.assertIn( '''
''', output.data) # Check that the close_status have its empty field self.assertIn( '''
''', output.data) # Check that the custom fields have their empty fields self.assertIn( '''
''', output.data) def test_view_forks(self): """ Test the view_forks endpoint. """ output = self.app.get('/foo/stats', follow_redirects=True) self.assertEqual(output.status_code, 404) tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/stats', follow_redirects=True) self.assertEqual(output.status_code, 200) self.assertTrue('This project has not been forked.' in output.data) @patch.dict('pagure.config.config', {'CASE_SENSITIVE': True}) def test_view_repo_case_sensitive(self): """ Test the view_repo endpoint. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test') self.assertEqual(output.status_code, 200) self.assertTrue('

This repo is brand new!

' in output.data) output = self.app.get('/TEST') self.assertEqual(output.status_code, 404) def test_view_repo_more_button_absent_no_auth(self): """ Test the view_repo endpoint and check if the "more" button is absent when not logged in. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertNotIn( 'This repo is brand new!

', output_text) self.assertIn( '
\n' 'test project #1
', output_text) self.assertIn( 'Stats ', output_text) self.perfMaxWalks(0, 0) self.perfReset() def test_view_repo_more_button_present(self): """ Test the view_repo endpoint and check if the "more" button is present when it should be. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/test') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertIn( '
This repo is brand new!

', output_text) self.assertIn( '
\n' 'test project #1
', output_text) self.assertIn( 'Stats ', output_text) self.perfMaxWalks(0, 0) self.perfReset() def test_view_repo_more_button_absent_no_access(self): """ Test the view_repo endpoint and check if the "more" button is absent if the user doesn't have access to the project. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) user = tests.FakeUser(username='foo') with tests.user_set(self.app.application, user): output = self.app.get('/test') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertNotIn( '
This repo is brand new!

', output_text) self.assertIn( '
\n' 'test project #1
', output_text) self.assertIn( 'Stats ', output_text) self.perfMaxWalks(0, 0) self.perfReset() def test_view_repo(self): """ Test the view_repo endpoint. """ output = self.app.get('/foo') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test') # No git repo associated self.assertEqual(output.status_code, 404) self.perfMaxWalks(0, 0) self.perfReset() tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test') self.assertEqual(output.status_code, 200) self.assertTrue('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertIn( 'Stats ', output.data) self.perfMaxWalks(0, 0) self.perfReset() output = self.app.get('/test/') self.assertEqual(output.status_code, 200) self.assertTrue('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.perfMaxWalks(0, 0) self.perfReset() # Add some content to the git repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'), 'README.txt') tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'), 'README.dummy') self.perfReset() # Authenticated, the Fork button appears user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/test') self.assertEqual(output.status_code, 200) self.assertIn( 'Fork', output.data) self.assertFalse('

This repo is brand new!

' in output.data) self.assertFalse('Forked from' in output.data) self.assertFalse('README.txt' in output.data) self.assertFalse('README.dummy' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.perfMaxWalks(3, 8) # Target: (1, 3) self.perfReset() # Non-authenticated, the Fork button does not appear output = self.app.get('/test') self.assertEqual(output.status_code, 200) self.assertNotIn( 'Fork', output.data) self.assertFalse('

This repo is brand new!

' in output.data) self.assertFalse('Forked from' in output.data) self.assertFalse('README.txt' in output.data) self.assertFalse('README.dummy' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.perfMaxWalks(3, 8) # Target: (1, 3) self.perfReset() # Turn that repo into a fork repo = pagure.lib.get_authorized_project(self.session, 'test') repo.parent_id = 2 repo.is_fork = True self.session.add(repo) self.session.commit() # View the repo in the UI output = self.app.get('/test') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) # Authenticated and already have a fork, the View Fork button appears user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/fork/pingou/test') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertTrue('Forked from' in output.data) self.assertNotIn( 'Fork', output.data) self.assertIn( ' View Fork', output.data) self.perfMaxWalks(1, 3) self.perfReset() # Authenticated, the Fork button appears user = tests.FakeUser(username='foo') with tests.user_set(self.app.application, user): output = self.app.get('/fork/pingou/test') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertTrue('Forked from' in output.data) self.assertNotIn( ' View Fork', output.data) self.assertIn( 'Fork', output.data) self.perfMaxWalks(1, 3) self.perfReset() # Non-authenticated, the Fork button does not appear output = self.app.get('/fork/pingou/test') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertTrue('Forked from' in output.data) self.assertNotIn( ' View Fork', output.data) self.assertNotIn( 'Fork', output.data) self.perfMaxWalks(1, 3) self.perfReset() # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou name='test3', description='test project #3', is_fork=True, parent_id=1, hook_token='aaabbbmmm', ) self.session.add(item) self.session.commit() tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), ncommits=10) output = self.app.get('/fork/pingou/test3') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #3
', output.data) self.assertTrue('Forked from' in output.data) self.perfMaxWalks(3, 18) # Ideal: (1, 3) self.perfReset() def test_view_repo_empty(self): """ Test the view_repo endpoint on a repo w/o master branch. """ tests.create_projects(self.session) # Create a git repo to play with gitrepo = os.path.join(self.path, 'repos', 'test.git') pygit2.init_repository(gitrepo, bare=True) # Create a fork of this repo newpath = tempfile.mkdtemp(prefix='pagure-viewrepo-test') new_repo = pygit2.clone_repository(gitrepo, newpath) # Edit the sources file again with open(os.path.join(newpath, 'sources'), 'w') as stream: stream.write('foo\n bar\nbaz\n boose') new_repo.index.add('sources') new_repo.index.write() # Commits the files added tree = new_repo.index.write_tree() author = pygit2.Signature( 'Alice Author', 'alice@authors.tld') committer = pygit2.Signature( 'Cecil Committer', 'cecil@committers.tld') new_repo.create_commit( 'refs/heads/feature', author, committer, 'A commit on branch feature', tree, [] ) refname = 'refs/heads/feature' ori_remote = new_repo.remotes[0] PagureRepo.push(ori_remote, refname) output = self.app.get('/test') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertFalse('Forked from' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertEqual( output.data.count(''), 0) shutil.rmtree(newpath) def test_view_repo_branch(self): """ Test the view_repo_branch endpoint. """ output = self.app.get('/foo/branch/master') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/branch/master') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/branch/master') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) output = self.app.get('/test/branch/master') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertFalse('Forked from' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) # Turn that repo into a fork repo = pagure.lib.get_authorized_project(self.session, 'test') repo.parent_id = 2 repo.is_fork = True self.session.add(repo) self.session.commit() # View the repo in the UI output = self.app.get('/test/branch/master') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) output = self.app.get('/fork/pingou/test/branch/master') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertTrue('Forked from' in output.data) # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou name='test3', description='test project #3', is_fork=True, parent_id=1, hook_token='aaabbbnnn', ) self.session.add(item) self.session.commit() tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), ncommits=10) output = self.app.get('/fork/pingou/test3/branch/master') self.assertEqual(output.status_code, 200) self.assertFalse('

This repo is brand new!

' in output.data) self.assertIn( '
\n' 'test project #3
', output.data) self.assertTrue('Forked from' in output.data) def test_view_commits(self): """ Test the view_commits endpoint. """ output = self.app.get('/foo/commits') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/commits') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/commits') self.assertEqual(output.status_code, 200) self.assertIn('

This repo is brand new!

', output.data) self.assertIn( '
\n' 'test project #1
', output.data) # Add some content to the git repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) output = self.app.get('/test/commits') self.assertEqual(output.status_code, 200) self.assertNotIn('

This repo is brand new!

', output.data) self.assertNotIn('Forked from', output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertIn('Commits - test - Pagure', output.data) output = self.app.get('/test/commits/master') self.assertEqual(output.status_code, 200) self.assertNotIn('

This repo is brand new!

', output.data) self.assertNotIn('Forked from', output.data) self.assertIn( '
\n' 'test project #1
', output.data) # Turn that repo into a fork repo = pagure.lib.get_authorized_project(self.session, 'test') repo.parent_id = 2 repo.is_fork = True self.session.add(repo) self.session.commit() # View the repo in the UI output = self.app.get('/test/commits') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) output = self.app.get('/fork/pingou/test/commits?page=abc') self.assertEqual(output.status_code, 200) self.assertNotIn('

This repo is brand new!

', output.data) self.assertIn( '
\n' 'test project #1
', output.data) self.assertIn('Forked from', output.data) # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou name='test3', description='test project #3', is_fork=True, parent_id=1, hook_token='aaabbbooo', ) self.session.add(item) self.session.commit() tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), ncommits=10) output = self.app.get('/fork/pingou/test3/commits/fobranch') self.assertEqual(output.status_code, 404) output = self.app.get('/fork/pingou/test3/commits') self.assertEqual(output.status_code, 200) self.assertNotIn('

This repo is brand new!

', output.data) self.assertIn( '
\n' 'test project #3
', output.data) self.assertIn('Forked from', output.data) def test_compare_commits(self): """ Test the compare_commits endpoint. """ # First two commits comparison def compare_first_two(c1, c2): # View commits comparison output = self.app.get('/test/c/%s..%s' % (c2.oid.hex, c1.oid.hex)) self.assertEqual(output.status_code, 200) self.assertIn( 'Diff from %s to %s - test\n - Pagure' % (c2.oid.hex, c1.oid.hex), output.data) self.assertIn( '
%s .. %s
' % (c2.oid.hex, c1.oid.hex), output.data) self.assertIn( 'Commits \n ' + '' + '\n 2\n ', output.data) self.assertIn( '- ' + 'Row 0', output.data) # View inverse commits comparison output = self.app.get('/test/c/%s..%s' % (c1.oid.hex, c2.oid.hex)) self.assertEqual(output.status_code, 200) self.assertIn( 'Diff from %s to %s - test\n - Pagure' % (c1.oid.hex, c2.oid.hex), output.data) self.assertIn( 'Commits \n ' + '' + '\n 2\n ', output.data) self.assertIn( '
%s .. %s
' % (c1.oid.hex, c2.oid.hex), output.data) self.assertIn( '' + '+ Row 0', output.data) def compare_all(c1, c3): # View commits comparison output = self.app.get('/test/c/%s..%s' % (c1.oid.hex, c3.oid.hex)) self.assertEqual(output.status_code, 200) self.assertIn( 'Diff from %s to %s - test\n - Pagure' % (c1.oid.hex, c3.oid.hex), output.data) self.assertIn( '
%s .. %s
' % (c1.oid.hex, c3.oid.hex), output.data) self.assertIn( '+ Row 0', output.data) self.assertEqual( output.data.count( '+ Row 0'), 2) self.assertIn( 'Commits \n ' + '' + '\n 3\n ', output.data) self.assertIn( 'title="View file as of 4829cf">Šource
', output.data) self.assertIn( '
file added
', output.data) # View inverse commits comparison output = self.app.get( '/test/c/%s..%s' % (c3.oid.hex, c1.oid.hex)) self.assertEqual(output.status_code, 200) self.assertIn( 'Diff from %s to %s - test\n - Pagure' % (c3.oid.hex, c1.oid.hex), output.data) self.assertIn( '
%s .. %s
' % (c3.oid.hex, c1.oid.hex), output.data) self.assertIn( '@@ -1,2 +1,1' + ' @@', output.data) self.assertIn( '- ' + 'Row 0', output.data) self.assertIn( 'Commits \n ' + '' + '\n 3\n ', output.data) self.assertIn( 'title="View file as of 000000">Šource', output.data) self.assertIn( '
file removed
', output.data) output = self.app.get('/foo/bar') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/bar') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/bar') self.assertEqual(output.status_code, 404) repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) # Add one commit to git repo tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'test.git'), ncommits=1) c1 = repo.revparse_single('HEAD') time.sleep(1) # Add another commit to git repo tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'test.git'), ncommits=1) c2 = repo.revparse_single('HEAD') time.sleep(1) # Add one more commit to git repo tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'test.git'), ncommits=1, filename='Šource') c3 = repo.revparse_single('HEAD') compare_first_two(c1, c2) compare_all(c1, c3) user = tests.FakeUser() # Set user logged in with tests.user_set(self.app.application, user): compare_first_two(c1, c2) compare_all(c1, c3) def test_view_file(self): """ Test the view_file endpoint. """ output = self.app.get('/foo/blob/foo/f/sources') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/blob/foo/f/sources') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/blob/foo/f/sources') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test.jpg') tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test_binary') output = self.app.get('/test/blob/master/foofile') self.assertEqual(output.status_code, 404) # View in a branch output = self.app.get('/test/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertTrue('' in output.data) self.assertTrue( '' in output.data) self.assertTrue( '' in output.data) # Empty files should also be displayed tests.add_content_to_git( os.path.join(self.path, 'repos', 'test.git'), filename="emptyfile.md", content="") output = self.app.get('/test/blob/master/f/emptyfile.md') self.assertEqual(output.status_code, 200) self.assertIn( 'Raw', output.data) self.assertIn( '
\n' ' \n
', output.data) # View what's supposed to be an image output = self.app.get('/test/blob/master/f/test.jpg') self.assertEqual(output.status_code, 200) self.assertIn( 'Binary files cannot be rendered.
', output.data) self.assertIn( 'view the raw version', output.data) # View by commit id repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) commit = repo.revparse_single('HEAD') output = self.app.get('/test/blob/%s/f/test.jpg' % commit.oid.hex) self.assertEqual(output.status_code, 200) self.assertIn( 'Binary files cannot be rendered.
', output.data) self.assertIn('/f/test.jpg">view the raw version', output.data) # View by image name -- somehow we support this output = self.app.get('/test/blob/sources/f/test.jpg') self.assertEqual(output.status_code, 200) self.assertIn( 'Binary files cannot be rendered.
', output.data) self.assertIn('/f/test.jpg">view the raw version', output.data) # View binary file output = self.app.get('/test/blob/sources/f/test_binary') self.assertEqual(output.status_code, 200) self.assertIn('/f/test_binary">view the raw version', output.data) self.assertTrue( 'Binary files cannot be rendered.
' in output.data) # View folder output = self.app.get('/test/blob/master/f/folder1') self.assertEqual(output.status_code, 200) self.assertIn( '', output.data) self.assertIn('Tree - test - Pagure', output.data) self.assertIn( '
', output.data) # Verify the nav links correctly when viewing a nested folder/file. output = self.app.get('/test/blob/master/f/folder1/folder2/file') self.assertEqual(output.status_code, 200) self.assertIn( '
  • \n' ' ' '  folder2\n' '
  • ', output.data) # View by image name -- with a non-existant file output = self.app.get('/test/blob/sources/f/testfoo.jpg') self.assertEqual(output.status_code, 404) output = self.app.get('/test/blob/master/f/folder1/testfoo.jpg') self.assertEqual(output.status_code, 404) # View file with a non-ascii name tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'test.git'), ncommits=1, filename='Šource') output = self.app.get('/test/blob/master/f/Šource') self.assertEqual(output.status_code, 200) self.assertEqual(output.headers['Content-Type'].lower(), 'text/html; charset=utf-8') self.assertIn('  Šource', output.data) self.assertIn('
     bar
    ', output.data) self.assertIn( '', output.data) self.assertTrue( '' in output.data or '' in output.data ) # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou name='test3', description='test project #3', is_fork=True, parent_id=1, hook_token='aaabbbppp', ) self.session.add(item) self.session.commit() tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), ncommits=10) # Verify the nav links correctly when viewing a file/folder in a fork. output = self.app.get( '/fork/pingou/test3/blob/master/f/folder1/folder2/file') self.assertEqual(output.status_code, 200) self.assertIn( '
  • \n' '   ' 'folder2\n
  • ', output.data) output = self.app.get('/fork/pingou/test3/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertIn('
    Row 0
    Row 0
    ', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) @patch( 'pagure.lib.encoding_utils.decode', MagicMock(side_effect=pagure.exceptions.PagureException)) def test_view_file_with_wrong_encoding(self): """ Test the view_file endpoint. """ tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) # Add some content to the git repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test.jpg') tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test_binary') # View file output = self.app.get('/test/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertIn('Binary files cannot be rendered.
    ', output.data) def test_view_raw_file(self): """ Test the view_raw_file endpoint. """ output = self.app.get('/foo/raw/foo/sources') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/raw/foo/sources') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/raw/foo/sources') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) # View first commit output = self.app.get('/test/raw/master') self.assertEqual(output.status_code, 200) self.assertEqual(output.headers['Content-Type'].lower(), 'text/plain; charset=ascii') self.assertTrue(':Author: Pierre-Yves Chibon' in output.data) # Add some more content to the repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test.jpg') tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test_binary') output = self.app.get('/test/raw/master/f/foofile') self.assertEqual(output.status_code, 404) # View in a branch output = self.app.get('/test/raw/master/f/sources') self.assertEqual(output.headers['Content-Type'].lower(), 'text/plain; charset=ascii') self.assertEqual(output.status_code, 200) self.assertTrue('foo\n bar' in output.data) # View what's supposed to be an image output = self.app.get('/test/raw/master/f/test.jpg') self.assertEqual(output.status_code, 200) self.assertTrue(output.data.startswith('\x00\x00\x01\x00')) # View by commit id repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) commit = repo.revparse_single('HEAD') output = self.app.get('/test/raw/%s/f/test.jpg' % commit.oid.hex) self.assertEqual(output.status_code, 200) self.assertTrue(output.data.startswith('\x00\x00\x01\x00')) # View by image name -- somehow we support this output = self.app.get('/test/raw/sources/f/test.jpg') self.assertEqual(output.status_code, 200) self.assertTrue(output.data.startswith('\x00\x00\x01\x00')) # View binary file output = self.app.get('/test/raw/sources/f/test_binary') self.assertEqual(output.status_code, 200) self.assertEqual(output.headers['Content-Type'].lower(), 'application/octet-stream') self.assertTrue(output.data.startswith('\x00\x00\x01\x00')) # View folder output = self.app.get('/test/raw/master/f/folder1') self.assertEqual(output.status_code, 404) # View by image name -- with a non-existant file output = self.app.get('/test/raw/sources/f/testfoo.jpg') self.assertEqual(output.status_code, 404) output = self.app.get('/test/raw/master/f/folder1/testfoo.jpg') self.assertEqual(output.status_code, 404) output = self.app.get('/test/raw/master/f/') self.assertEqual(output.status_code, 404) output = self.app.get('/test/raw/master') self.assertEqual(output.status_code, 200) self.assertEqual(output.headers['Content-Type'].lower(), 'text/plain; charset=ascii') self.assertTrue(output.data.startswith( 'diff --git a/test_binary b/test_binary\n')) output = self.app.get('/test/raw/%s' % commit.oid.hex) self.assertEqual(output.status_code, 200) self.assertTrue(output.data.startswith( 'diff --git a/test_binary b/test_binary\n')) # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou name='test3', description='test project #3', is_fork=True, parent_id=1, hook_token='aaabbbqqq', ) self.session.add(item) self.session.commit() tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), ncommits=10) output = self.app.get('/fork/pingou/test3/raw/master/f/sources') self.assertEqual(output.status_code, 200) self.assertEqual(output.headers['Content-Type'].lower(), 'text/plain; charset=ascii') self.assertTrue('foo\n bar' in output.data) def test_view_blame_file(self): """ Test the view_blame_file endpoint. """ output = self.app.get('/foo/blame/sources') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/blame/sources') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/blame/sources') self.assertEqual(output.status_code, 404) # Add some content to the git repo tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_content_git_repo( os.path.join(self.path, 'repos', 'test.git'), branch='feature') tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test.jpg') tests.add_binary_git_repo( os.path.join(self.path, 'repos', 'test.git'), 'test_binary') output = self.app.get('/test/blame/foofile') self.assertEqual(output.status_code, 404) regex = re.compile('>(\w+)\n
     barRow 0
    ') # View in master branch output = self.app.get('/test/blame/sources') self.assertEqual(output.status_code, 200) self.assertIn(b'', output.data) self.assertIn( b'', output.data) self.assertIn( b'', output.data) data = regex.findall(output.data) self.assertEqual(len(data), 2) # View for a commit repo_obj = pygit2.Repository( os.path.join(self.path, 'repos', 'test.git')) commit = repo_obj[repo_obj.head.target] parent = commit.parents[0].oid.hex output = self.app.get('/test/blame/sources?identifier=%s' % parent) self.assertEqual(output.status_code, 200) self.assertIn(b'
     bar
    ', output.data) self.assertIn( b'', output.data) self.assertIn( b'', output.data) data = regex.findall(output.data) self.assertEqual(len(data), 2) # View in feature branch output = self.app.get('/test/blame/sources?identifier=feature') self.assertEqual(output.status_code, 200) self.assertIn(b'
     bar
    ', output.data) self.assertIn( b'', output.data) self.assertIn( b'', output.data) data2 = regex.findall(output.data) self.assertEqual(len(data2), 2) self.assertNotEqual(data, data2) # View what's supposed to be an image output = self.app.get('/test/blame/test.jpg') self.assertEqual(output.status_code, 400) self.assertIn( b'400 Bad Request', output.data) self.assertIn( b'

    Binary files cannot be blamed

    ', output.data) # View folder output = self.app.get('/test/blame/folder1') self.assertEqual(output.status_code, 404) self.assertIn("Page not found :'( - Pagure", output.data) self.assertIn( '

    Page not found (404)

    ', output.data) # View by image name -- with a non-existant file output = self.app.get('/test/blame/testfoo.jpg') self.assertEqual(output.status_code, 404) output = self.app.get('/test/blame/folder1/testfoo.jpg') self.assertEqual(output.status_code, 404) # View file with a non-ascii name tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'test.git'), ncommits=1, filename='Šource') output = self.app.get('/test/blame/Šource') self.assertEqual(output.status_code, 200) self.assertEqual(output.headers['Content-Type'].lower(), 'text/html; charset=utf-8') self.assertIn('  Šource', output.data) self.assertIn('
     bar
    ', output.data) self.assertIn( '', output.data) self.assertTrue( '' in output.data or '' in output.data ) # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou name='test3', description='test project #3', is_fork=True, parent_id=1, hook_token='aaabbbppp', ) self.session.add(item) self.session.commit() tests.add_content_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) tests.add_commit_git_repo( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), ncommits=10) tests.add_content_to_git( os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), content=u'✨☃🍰☃✨'.encode('utf-8')) output = self.app.get('/fork/pingou/test3/blame/sources') self.assertEqual(output.status_code, 200) self.assertIn('
    Row 0
    Row 0
    ', output.data) self.assertIn( '', output.data) self.assertIn( '', output.data) def test_view_blame_file_on_tag(self): """ Test the view_blame_file endpoint. """ regex = re.compile('>(\w+)\n
     barRow 0
    ') tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) # Add some content to the git repo tests.add_content_git_repo( os.path.join(self.path, 'repos', 'test.git')) tests.add_readme_git_repo( os.path.join(self.path, 'repos', 'test.git')) # add a tag to the git repo repo = pygit2.Repository( os.path.join(self.path, 'repos', 'test.git')) commit = repo[repo.head.target] tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0) repo.create_tag( 'v1.0', commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger, "Release v1.0") # View for tag v1.0 output = self.app.get('/test/blame/sources?identifier=v1.0') self.assertEqual(output.status_code, 200) self.assertIn(b'', output.data) self.assertIn( b'', output.data) self.assertIn( b'', output.data) data = regex.findall(output.data) self.assertEqual(len(data), 2) def test_view_commit(self): """ Test the view_commit endpoint. """ output = self.app.get('/foo/c/bar') # No project registered in the DB self.assertEqual(output.status_code, 404) tests.create_projects(self.session) output = self.app.get('/test/c/bar') # No git repo associated self.assertEqual(output.status_code, 404) tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) output = self.app.get('/test/c/bar') self.assertEqual(output.status_code, 404) # 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/c/%s' % commit.oid.hex) self.assertEqual(output.status_code, 200) self.assertTrue( '
     bar