From 7a673363a193b439a3ab7c1ab48b1151208fda6d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 27 2017 10:30:45 +0000 Subject: Raise an exception if the user tries to set a priority not in the repo --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index b53456d..3c13620 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1443,8 +1443,10 @@ def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, priority = int(priority) except (ValueError, TypeError): priority = None - if str(priority) not in priorities: - priority = None + if priorities and priority and str(priority) not in priorities: + raise pagure.exceptions.PagureException( + 'You are trying to create an issue with a priority that does ' + 'not exist in the project.') issue = model.Issue( id=issue_id or get_next_id(session, repo.id), diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index e7ebd11..29c8ea2 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1557,25 +1557,44 @@ index 0000000..60f7480 "priority": 1, } + self.assertRaises( + pagure.exceptions.PagureException, + pagure.lib.git.update_ticket_from_git, + self.session, + reponame='foobar', + namespace=None, + username=None, + issue_uid='foobar', + json_data=data + ) + + # Create the issue + data = { + "status": "Open", "title": "foo", "comments": [], + "content": "bar", "date_created": "1426500263", + "user": { + "name": "pingou", "emails": ["pingou@fedoraproject.org"]}, + "milestone": "Next Release", + "priority": 1, + } + pagure.lib.git.update_ticket_from_git( self.session, reponame='test', namespace=None, username=None, issue_uid='foobar', json_data=data ) self.session.commit() - # Data contained a priority but not the project, so bailing - self.assertEqual(len(repo.issues), 1) - self.assertEqual(repo.issues[0].id, 1) - self.assertEqual(repo.issues[0].uid, 'foobar') - self.assertEqual(repo.issues[0].title, 'foo') - self.assertEqual(repo.issues[0].depending_text, []) - self.assertEqual(repo.issues[0].blocking_text, []) - self.assertEqual(repo.issues[0].milestone, 'Next Release') - self.assertEqual(repo.issues[0].priority, None) - self.assertEqual(repo.milestones, {'Next Release': None}) - # Edit the issue + data = { + "status": "Open", "title": "foo", "comments": [], + "content": "bar", "date_created": "1426500263", + "user": { + "name": "pingou", "emails": ["pingou@fedoraproject.org"]}, + "milestone": "Next Release", + "priority": 1, + } + pagure.lib.git.update_ticket_from_git( self.session, reponame='test', namespace=None, username=None, issue_uid='foobar', json_data=data