From bbcf0f63b001dc310bdee90bea3978569b7f2833 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 24 2017 11:48:54 +0000 Subject: [PATCH 1/2] Include the priority name in the notification rather than its level Adjusts this for the new and the old value and do not set a priority if the level specified isn't present in the levels of priority of the project. Fixes https://pagure.io/pagure/issue/2158 --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 4138ea5..df645dd 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1630,17 +1630,23 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, msg += ' (was: %s)' % old_status messages.append(msg) if priority != -1: + priorities = issue.project.priorities try: priority = int(priority) except (ValueError, TypeError): priority = None + + if str(priority) not in priorities: + priority = None + if priority != issue.priority: old_priority = issue.priority issue.priority = priority edit.append('priority') - msg = 'Issue priority set to: %s' % priority + msg = 'Issue priority set to: %s' % priorities[str(priority)] if old_priority: - msg += ' (was: %s)' % old_priority + msg += ' (was: %s)' % priorities.get( + str(old_priority), old_priority) messages.append(msg) if private in [True, False] and private != issue.private: old_private = issue.private From 94274b513f2ff853c57dabd53e114805a8b05360 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 24 2017 11:49:38 +0000 Subject: [PATCH 2/2] Add unit-tests for updating the priority field of a ticket --- diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index c0b307d..0abb498 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -327,6 +327,71 @@ class PagureLibtests(tests.Modeltests): @patch('pagure.lib.git.update_git') @patch('pagure.lib.notify.send_email') + def test_edit_issue_priority(self, p_send_email, p_ugt): + """ Test the edit_issue of pagure.lib when changing the priority. + """ + p_send_email.return_value = True + p_ugt.return_value = True + + self.test_new_issue() + + repo = pagure.lib.get_project(self.session, 'test') + issue = pagure.lib.search_issues(self.session, repo, issueid=2) + + # Set some priorities to the repo + repo = pagure.lib.get_project(self.session, 'test') + repo.priorities = {'1': 'High', '2': 'Normal'} + self.session.add(repo) + self.session.commit() + + self.assertEqual(repo.open_tickets, 2) + self.assertEqual(repo.open_tickets_public, 2) + + # Edit the issue -- Wrong priority value: No changes + msg = pagure.lib.edit_issue( + session=self.session, + issue=issue, + user='pingou', + ticketfolder=None, + priority=3, + ) + self.session.commit() + self.assertEqual(msg, None) + + # Edit the issue -- Good priority + msg = pagure.lib.edit_issue( + session=self.session, + issue=issue, + user='pingou', + ticketfolder=None, + priority=2, + ) + self.session.commit() + self.assertEqual( + msg, + [ + 'Issue priority set to: Normal' + ] + ) + + # Edit the issue -- Update priority + msg = pagure.lib.edit_issue( + session=self.session, + issue=issue, + user='pingou', + ticketfolder=None, + priority=1, + ) + self.session.commit() + self.assertEqual( + msg, + [ + 'Issue priority set to: High (was: Normal)' + ] + ) + + @patch('pagure.lib.git.update_git') + @patch('pagure.lib.notify.send_email') def test_edit_issue_depending(self, p_send_email, p_ugt): """ Test the edit_issue of pagure.lib when the issue depends on another.