| |
@@ -14,6 +14,7 @@
|
| |
import datetime
|
| |
import json
|
| |
import unittest
|
| |
+ import re
|
| |
import shutil
|
| |
import sys
|
| |
import tempfile
|
| |
@@ -204,6 +205,22 @@
|
| |
self.assertIn('Deploy key added', output.data)
|
| |
self.assertIn('PUSH ACCESS', output.data)
|
| |
|
| |
+ @patch('pagure.ui.repo.admin_session_timedout')
|
| |
+ @patch.dict('pagure.APP.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(pagure.APP, 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.ui.repo.admin_session_timedout')
|
| |
def test_add_user(self, ast):
|
| |
@@ -513,7 +530,6 @@
|
| |
|
| |
pagure.APP.config['ENABLE_USER_MNGT'] = True
|
| |
|
| |
-
|
| |
@patch('pagure.ui.repo.admin_session_timedout')
|
| |
def test_remove_deploykey(self, ast):
|
| |
""" Test the remove_deploykey endpoint. """
|
| |
@@ -589,6 +605,20 @@
|
| |
self.assertIn('<h3>Settings for test</h3>', output.data)
|
| |
self.assertIn('Deploy key removed', output.data)
|
| |
|
| |
+ @patch('pagure.ui.repo.admin_session_timedout')
|
| |
+ @patch.dict('pagure.APP.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(pagure.APP, user):
|
| |
+ output = self.app.post('/test/dropdeploykey/1')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
|
| |
@patch('pagure.ui.repo.admin_session_timedout')
|
| |
def test_remove_user(self, ast):
|
| |
@@ -640,6 +670,7 @@
|
| |
|
| |
# Add an user to a project
|
| |
repo = pagure.get_authorized_project(self.session, 'test')
|
| |
+ self.assertEqual(len(repo.users), 0)
|
| |
msg = pagure.lib.add_user_to_project(
|
| |
session=self.session,
|
| |
project=repo,
|
| |
@@ -648,6 +679,7 @@
|
| |
)
|
| |
self.session.commit()
|
| |
self.assertEqual(msg, 'User added')
|
| |
+ self.assertEqual(len(repo.users), 1)
|
| |
|
| |
with tests.user_set(pagure.APP, user):
|
| |
output = self.app.post('/test/dropuser/2', follow_redirects=True)
|
| |
@@ -657,6 +689,9 @@
|
| |
self.assertIn('<h3>Settings for test</h3>', output.data)
|
| |
self.assertNotIn(
|
| |
'</button>\n User removed', output.data)
|
| |
+ self.assertIn('action="/test/dropuser/2">', output.data)
|
| |
+ repo = pagure.get_authorized_project(self.session, 'test')
|
| |
+ self.assertEqual(len(repo.users), 1)
|
| |
|
| |
data = {'csrf_token': csrf_token}
|
| |
output = self.app.post(
|
| |
@@ -667,6 +702,9 @@
|
| |
self.assertIn('<h3>Settings for test</h3>', output.data)
|
| |
self.assertIn(
|
| |
'</button>\n User removed', output.data)
|
| |
+ self.assertNotIn('action="/test/dropuser/2">', output.data)
|
| |
+ repo = pagure.get_authorized_project(self.session, 'test')
|
| |
+ self.assertEqual(len(repo.users), 0)
|
| |
|
| |
|
| |
@patch('pagure.ui.repo.admin_session_timedout')
|
| |
@@ -1252,6 +1290,20 @@
|
| |
self.assertEqual(output.status_code, 200)
|
| |
self.assertTrue('This project has not been forked.' in output.data)
|
| |
|
| |
+ @patch.dict('pagure.APP.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('<p>This repo is brand new!</p>' in output.data)
|
| |
+
|
| |
+ output = self.app.get('/TEST')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
+
|
| |
def test_view_repo(self):
|
| |
""" Test the view_repo endpoint. """
|
| |
|
| |
@@ -2072,6 +2124,9 @@
|
| |
# 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')
|
| |
@@ -2080,8 +2135,9 @@
|
| |
|
| |
output = self.app.get('/test/blame/foofile')
|
| |
self.assertEqual(output.status_code, 404)
|
| |
+ regex = re.compile('>(\w+)</a></td>\n<td class="cell2">')
|
| |
|
| |
- # View in a branch
|
| |
+ # View in master branch
|
| |
output = self.app.get('/test/blame/sources')
|
| |
self.assertEqual(output.status_code, 200)
|
| |
self.assertIn(b'<table class="code_table">', output.data)
|
| |
@@ -2090,6 +2146,21 @@
|
| |
b'data-line-number="1"></a></td>', output.data)
|
| |
self.assertIn(
|
| |
b'<td class="cell2"><pre> bar</pre></td>', 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'<table class="code_table">', output.data)
|
| |
+ self.assertIn(
|
| |
+ b'<tr><td class="cell1"><a id="1" href="#1" '
|
| |
+ b'data-line-number="1"></a></td>', output.data)
|
| |
+ self.assertIn(
|
| |
+ b'<td class="cell2"><pre> bar</pre></td>', 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')
|
| |
@@ -3799,6 +3870,43 @@
|
| |
self.assertIn('This project has not been tagged.', output.data)
|
| |
|
| |
@patch('pagure.ui.repo.admin_session_timedout')
|
| |
+ def test_add_token_all_tokens(self, ast):
|
| |
+ """ Test the add_token endpoint. """
|
| |
+ ast.return_value = False
|
| |
+ 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(pagure.APP, user):
|
| |
+ output = self.app.get('/test/token/new/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertIn('<strong>Create a new token</strong>', output.data)
|
| |
+ self.assertEqual(
|
| |
+ output.data.count('<label class="c-input c-checkbox">'),
|
| |
+ len(pagure.APP.config['ACLS'].keys())
|
| |
+ )
|
| |
+
|
| |
+ @patch.dict('pagure.APP.config', {'USER_ACLS': ['create_project']})
|
| |
+ @patch('pagure.ui.repo.admin_session_timedout')
|
| |
+ def test_add_token_one_token(self, ast):
|
| |
+ """ Test the add_token endpoint. """
|
| |
+ ast.return_value = False
|
| |
+ 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(pagure.APP, user):
|
| |
+ output = self.app.get('/test/token/new/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertIn('<strong>Create a new token</strong>', output.data)
|
| |
+ self.assertEqual(
|
| |
+ output.data.count('<label class="c-input c-checkbox">'),
|
| |
+ 1
|
| |
+ )
|
| |
+
|
| |
+ @patch('pagure.ui.repo.admin_session_timedout')
|
| |
def test_add_token(self, ast):
|
| |
""" Test the add_token endpoint. """
|
| |
ast.return_value = False
|
| |
@@ -4050,6 +4158,51 @@
|
| |
'<strong title="Currently viewing branch master"',
|
| |
output.data)
|
| |
|
| |
+ @patch.dict('pagure.APP.config', {'ALLOW_DELETE_BRANCH': False})
|
| |
+ def test_delete_branch_disabled_in_ui(self):
|
| |
+ """ Test that the delete branch button doesn't show when the feature
|
| |
+ is turned off. """
|
| |
+ tests.create_projects(self.session)
|
| |
+ tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
| |
+
|
| |
+ # Add a branch that we can delete
|
| |
+ path = os.path.join(self.path, 'repos', 'test.git')
|
| |
+ tests.add_content_git_repo(path)
|
| |
+ repo = pygit2.Repository(path)
|
| |
+ repo.create_branch('foo', repo.head.get_object())
|
| |
+
|
| |
+ user = tests.FakeUser(username = 'pingou')
|
| |
+ with tests.user_set(pagure.APP, user):
|
| |
+ # Check that the UI doesn't offer the button
|
| |
+ output = self.app.get('/test')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertIn(
|
| |
+ 'data-toggle="tooltip">foo',
|
| |
+ output.data)
|
| |
+ self.assertNotIn('<form id="delete_branch_form-foo"', output.data)
|
| |
+ self.assertNotIn(
|
| |
+ 'Are you sure you want to remove the branch',
|
| |
+ output.data)
|
| |
+
|
| |
+ @patch.dict('pagure.APP.config', {'ALLOW_DELETE_BRANCH': False})
|
| |
+ def test_delete_branch_disabled(self):
|
| |
+ """ Test the delete_branch endpoint when it's disabled in the entire
|
| |
+ instance. """
|
| |
+ tests.create_projects(self.session)
|
| |
+ tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
| |
+
|
| |
+ # Add a branch that we can delete
|
| |
+ path = os.path.join(self.path, 'repos', 'test.git')
|
| |
+ tests.add_content_git_repo(path)
|
| |
+ repo = pygit2.Repository(path)
|
| |
+ repo.create_branch('foo', repo.head.get_object())
|
| |
+
|
| |
+ user = tests.FakeUser(username = 'pingou')
|
| |
+ with tests.user_set(pagure.APP, user):
|
| |
+ # Delete the branch
|
| |
+ output = self.app.post('/test/b/foo/delete', follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
+
|
| |
def test_view_docs(self):
|
| |
""" Test the view_docs endpoint. """
|
| |
output = self.app.get('/docs/foo/')
|
| |