← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wallyworld/launchpad/rabbit-enum-oops-972998 into lp:launchpad

 

Ian Booth has proposed merging lp:~wallyworld/launchpad/rabbit-enum-oops-972998 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #972998 in Launchpad itself: "TypeError: <DBItem InformationType> is not JSON serializable"
  https://bugs.launchpad.net/launchpad/+bug/972998

For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/rabbit-enum-oops-972998/+merge/103210

== Implementation ==

The Bug.transitionToInformationType() method was incorrectly constructing the object modified event. The information_type value was being used for the edited_field, not the field name.

== Tests ==

Add test to check the event.

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/model/bug.py
  lib/lp/bugs/model/tests/test_bug.py
-- 
https://code.launchpad.net/~wallyworld/launchpad/rabbit-enum-oops-972998/+merge/103210
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wallyworld/launchpad/rabbit-enum-oops-972998 into lp:launchpad.
=== modified file 'lib/lp/bugs/model/bug.py'
--- lib/lp/bugs/model/bug.py	2012-04-19 21:15:25 +0000
+++ lib/lp/bugs/model/bug.py	2012-04-24 04:35:27 +0000
@@ -1786,7 +1786,7 @@
         self._security_related = (
             information_type in SECURITY_INFORMATION_TYPES)
         notify(ObjectModifiedEvent(
-                self, bug_before_modification, [information_type], user=who))
+                self, bug_before_modification, ['information_type'], user=who))
         return True
 
     def getRequiredSubscribers(self, information_type, who):

=== modified file 'lib/lp/bugs/model/tests/test_bug.py'
--- lib/lp/bugs/model/tests/test_bug.py	2012-04-19 21:15:25 +0000
+++ lib/lp/bugs/model/tests/test_bug.py	2012-04-24 04:35:27 +0000
@@ -8,6 +8,7 @@
     timedelta,
     )
 
+from lazr.lifecycle.interfaces import IObjectModifiedEvent
 from pytz import UTC
 from storm.expr import Join
 from storm.store import Store
@@ -21,6 +22,7 @@
     BugNotificationStatus,
     )
 from lp.bugs.errors import BugCannotBePrivate
+from lp.bugs.interfaces.bug import IBug
 from lp.bugs.interfaces.bugnotification import IBugNotificationSet
 from lp.bugs.interfaces.bugtask import BugTaskStatus
 from lp.bugs.mail.bugnotificationrecipients import BugNotificationRecipients
@@ -42,6 +44,7 @@
     StormStatementRecorder,
     TestCaseWithFactory,
     )
+from lp.testing.event import TestEventListener
 from lp.testing.layers import DatabaseFunctionalLayer
 from lp.testing.matchers import (
     Equals,
@@ -864,6 +867,25 @@
             )
         [self.assertEqual(m[1], m[0].information_type) for m in mapping]
 
+    def test_information_type_modified_event(self):
+        # When a bug's information_type is changed, the expected object
+        # modified event is published.
+        self.event_edited_fields = []
+        self.event_object = None
+
+        def event_callback(object, event):
+            self.event_edited_fields = event.edited_fields
+            self.event_object = event.object
+
+        TestEventListener(IBug, IObjectModifiedEvent, event_callback)
+        owner = self.factory.makePerson()
+        bug = self.factory.makeBug(
+            private=True, security_related=True, owner=owner)
+        with person_logged_in(owner):
+            bug.transitionToInformationType(InformationType.PUBLIC, owner)
+        self.assertEqual(['information_type'], self.event_edited_fields)
+        self.assertEqual(bug, self.event_object)
+
     def test_private_to_public_information_type(self):
         # A private bug transitioning to public has the correct information
         # type.


Follow ups