From 3a9d23e05b4d1f3ebc0dc22203b77ef507dfa9ea Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 16 2017 10:00:35 +0000 Subject: [PATCH 1/2] Always include a blank priority field This will make an empty priority row in the html which is then used as template for when adding another row or the default priorities Fixes https://pagure.io/pagure/issue/1917 Fixes https://pagure.io/pagure/issue/1915 --- diff --git a/pagure/templates/settings.html b/pagure/templates/settings.html index 2fa5df0..2e58bf3 100644 --- a/pagure/templates/settings.html +++ b/pagure/templates/settings.html @@ -609,7 +609,7 @@
- {% for priority in ((repo.priorities or []) | sort) %} + {% for priority in ((repo.priorities or [""]) | sort) %}
Date: Feb 16 2017 10:00:35 +0000 Subject: [PATCH 2/2] Add unit-tests checking the default rendering of some fields in settings This should let us avoid re-running into the bug we had where since we had no priorities in the project nor in template, we had no rows for priorities in the settings page and thus could neither add a new row or add the default set. --- diff --git a/pagure/templates/settings.html b/pagure/templates/settings.html index 2e58bf3..1bc8fb7 100644 --- a/pagure/templates/settings.html +++ b/pagure/templates/settings.html @@ -574,7 +574,6 @@
{% endif %} - {% if config.get('ENABLE_TICKETS', True) and repo.settings.get('issue_tracker', True) %}
diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 9f50006..bca04f5 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -1138,6 +1138,110 @@ class PagureFlaskRepotests(tests.Modeltests): '', output.data) + @patch('pagure.ui.repo.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(pagure.APP, 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(self.path) + + 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(pagure.APP, 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. """