Source

trac-mq / t11148 / t11148_r11784_IEntityListener_compat_ticket.diff

# HG changeset patch
# Parent 2c0e5eb15b91dc6952dcb8c0866631ff7cb9fcab
Trac #11148 : 'ITicketChangeListener' , 'IMilestoneChangeListener' notifications powered by 'ListenerNotifier.notify'

diff -r 2c0e5eb15b91 trac/ticket/model.py
--- a/trac/ticket/model.py	Sat Apr 27 16:50:19 2013 -0500
+++ b/trac/ticket/model.py	Sat Apr 27 17:39:07 2013 -0500
@@ -1116,8 +1116,8 @@
             del self.cache.milestones
             TicketSystem(self.env).reset_ticket_fields()
 
-        for listener in TicketSystem(self.env).milestone_change_listeners:
-            listener.milestone_deleted(self)
+        ListenerNotifier(self.env).notify(
+                IMilestoneChangeListener.milestone_deleted, entity=self)
 
     def insert(self, db=None):
         """Insert a new milestone.
@@ -1138,8 +1138,8 @@
             self.checkin()
             TicketSystem(self.env).reset_ticket_fields()
 
-        for listener in TicketSystem(self.env).milestone_change_listeners:
-            listener.milestone_created(self)
+        ListenerNotifier(self.env).notify(
+                IMilestoneChangeListener.milestone_created, entity=self)
 
     def update(self, db=None):
         """Update the milestone.
@@ -1177,8 +1177,9 @@
 
         old_values = dict((k, v) for k, v in old.iteritems()
                           if getattr(self, k) != v)
-        for listener in TicketSystem(self.env).milestone_change_listeners:
-            listener.milestone_changed(self, old_values)
+        ListenerNotifier(self.env).notify(
+                IMilestoneChangeListener.milestone_changed,
+                entity=self, old_values=old_values)
 
     @classmethod
     def select(cls, env, include_completed=True, db=None):
diff -r 2c0e5eb15b91 trac/ticket/tests/model.py
--- a/trac/ticket/tests/model.py	Sat Apr 27 16:50:19 2013 -0500
+++ b/trac/ticket/tests/model.py	Sat Apr 27 17:39:07 2013 -0500
@@ -993,13 +993,20 @@
 
     def test_change_listener_created(self):
         listener = TestMilestoneChangeListener(self.env)
+        generic_listener = GenericEntitiesChangeListenerMock(self.env)
+
         milestone = self._create_milestone(name='Milestone 1')
         milestone.insert()
         self.assertEqual('created', listener.action)
         self.assertEqual(milestone, listener.milestone)
 
+        self.assertEqual([{'action' : 'created', 'entity' : milestone}], 
+                         generic_listener.details)
+
     def test_change_listener_changed(self):
         listener = TestMilestoneChangeListener(self.env)
+        generic_listener = GenericEntitiesChangeListenerMock(self.env)
+
         milestone = self._create_milestone(
             name='Milestone 1',
             due=datetime(2001, 01, 01, tzinfo=utc),
@@ -1017,8 +1024,18 @@
                           'description': 'The milestone description'},
                          listener.old_values)
 
+        self.assertEqual([{'action' : 'created', 'entity' : milestone},
+                          {'action' : 'changed', 'entity' : milestone,
+                           'old_values' : {'name': 'Milestone 1', 
+                                           'completed': None,
+                                           'description': 'The milestone '
+                                                          'description'}}], 
+                         generic_listener.details)
+
     def test_change_listener_deleted(self):
         listener = TestMilestoneChangeListener(self.env)
+        generic_listener = GenericEntitiesChangeListenerMock(self.env)
+
         milestone = self._create_milestone(name='Milestone 1')
         milestone.insert()
         self.assertEqual(True, milestone.exists)
@@ -1028,6 +1045,10 @@
         self.assertEqual('deleted', listener.action)
         self.assertEqual(milestone, listener.milestone)
 
+        self.assertEqual([{'action' : 'created', 'entity' : milestone},
+                          {'action' : 'deleted', 'entity' : milestone}], 
+                         generic_listener.details)
+
 
 class ComponentTestCase(unittest.TestCase):