diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index 52a43b8..ea4d273 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -628,7 +628,6 @@ class PagureFlaskRepotests(tests.Modeltests):
'\n Group removed',
output.data)
-
@patch('pagure.ui.repo.admin_session_timedout')
def test_update_project(self, ast):
""" Test the update_project endpoint. """
@@ -726,6 +725,82 @@ class PagureFlaskRepotests(tests.Modeltests):
output.data)
@patch('pagure.ui.repo.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 complain
+ (rightfully) about duplicated content.
+ This test ensure we are behaving properly.
+ """
+ ast.return_value = False
+
+ tests.create_projects(self.session)
+ tests.create_projects_git(self.path)
+
+ user = tests.FakeUser(username='pingou')
+ with tests.user_set(pagure.APP, 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.ui.repo.admin_session_timedout')
def test_view_settings(self, ast):
""" Test the view_settings endpoint. """
ast.return_value = False