From 7b3aee5f2c9b8617346632505913472789bdcbd1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 01 2016 08:17:57 +0000 Subject: Allow resetting the priorities of a project If a project wants to drop all the priorities it should be able to do so without breaking the list of issues page nor having showing the priority field on the issue page. --- diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index b4f3dee..45f32f6 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -527,9 +527,10 @@ def largest_priority(dictionary): """ Template filter to return the largest priority +1 """ if dictionary: - return max([int(k) for k in dictionary if k]) + 1 - else: - return 1 + keys = [int(k) for k in dictionary if k] + if keys: + return max(keys) + 1 + return 1 @APP.template_filter('unicode') diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 5b349b0..8d964a9 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -1179,9 +1179,10 @@ def update_priorities(repo, username=None, namespace=None): if not error: priorities = {} - for cnt in range(len(weights)): - priorities[weights[cnt]] = titles[cnt] - priorities[''] = '' + if weights: + for cnt in range(len(weights)): + priorities[weights[cnt]] = titles[cnt] + priorities[''] = '' try: repo.priorities = priorities SESSION.add(repo) diff --git a/tests/test_pagure_flask_ui_priorities.py b/tests/test_pagure_flask_ui_priorities.py index 03cf122..f73a0ae 100644 --- a/tests/test_pagure_flask_ui_priorities.py +++ b/tests/test_pagure_flask_ui_priorities.py @@ -347,6 +347,105 @@ class PagureFlaskPrioritiestests(tests.Modeltests): '/test/update/priorities', data=data) self.assertEqual(output.status_code, 403) + @patch('pagure.lib.git.update_git') + @patch('pagure.lib.notify.send_email') + def test_reset_priorities(self, p_send_email, p_ugt): + """ Test resetting the priorities of a repo. """ + p_send_email.return_value = True + p_ugt.return_value = True + + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path), bare=True) + + # Start from scrach on priorities + repo = pagure.lib.get_project(self.session, 'test') + self.assertEqual(repo.priorities, {}) + + user = tests.FakeUser() + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + + # Get the CSRF token + 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] + + # Set some priorities + data = { + 'priority_weigth': [1, 2, 3], + 'priority_title': ['High', 'Normal', 'Low'], + 'csrf_token': csrf_token, + } + output = self.app.post( + '/test/update/priorities', 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) + + # Check the result of the action -- Priority recorded + repo = pagure.lib.get_project(self.session, 'test') + self.assertEqual( + repo.priorities, + {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'Low'} + ) + + # Create an issue + data = { + 'title': 'Test issue', + 'issue_content': 'We really should improve on this issue', + 'status': 'Open', + 'csrf_token': csrf_token, + } + output = self.app.post( + '/test/new_issue', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Issue #1: Test issue - test - Pagure', + output.data) + self.assertIn( + '', + output.data) + self.assertIn('
', output.data) + self.assertIn('', output.data) + + # Check that the ticket *does* have priorities + output = self.app.get('/test/issue/1') + self.assertEqual(output.status_code, 200) + self.assertIn('
', output.data) + self.assertIn('', output.data) + + # Reset the priorities + data = { + 'csrf_token': csrf_token, + } + output = self.app.post( + '/test/update/priorities', 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) + + # Check that the issue list renders fine + output = self.app.get('/test/issues') + self.assertEqual(output.status_code, 200) + + # Check that the ticket *does not* have priorities + output = self.app.get('/test/issue/1') + self.assertEqual(output.status_code, 200) + self.assertNotIn('
', output.data) + self.assertNotIn('', output.data) + + # Check the result of the action -- Priority recorded + repo = pagure.lib.get_project(self.session, 'test') + self.assertEqual(repo.priorities, {}) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(