1. Olemis Lang
  2. trac-mq

Commits

Olemis Lang  committed dffc687

Trac #11148 : Updated test case for custom event method

  • Participants
  • Parent commits fdf642e
  • Branches trac_t11148

Comments (0)

Files changed (1)

File t11148/t11148_r11782_IEntityChangeListener_v2.diff

View file
  • Ignore whitespace
 
 diff -r 8d0c3223a818 trac/core.py
 --- a/trac/core.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/core.py	Wed Apr 24 19:11:37 2013 -0500
++++ b/trac/core.py	Wed Apr 24 19:29:38 2013 -0500
 @@ -165,7 +165,6 @@
  
          locals_.setdefault('_implements', []).extend(interfaces)
 +                getattr(listener, method_name)(**kwargs)
 diff -r 8d0c3223a818 trac/ticket/model.py
 --- a/trac/ticket/model.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/ticket/model.py	Wed Apr 24 19:11:37 2013 -0500
++++ b/trac/ticket/model.py	Wed Apr 24 19:29:38 2013 -0500
 @@ -25,7 +25,8 @@
  from trac.attachment import Attachment
  from trac import core
          """
 diff -r 8d0c3223a818 trac/ticket/tests/model.py
 --- a/trac/ticket/tests/model.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/ticket/tests/model.py	Wed Apr 24 19:11:37 2013 -0500
++++ b/trac/ticket/tests/model.py	Wed Apr 24 19:29:38 2013 -0500
 @@ -9,11 +9,11 @@
  
  from trac import core
  from trac.ticket.api import (
      IMilestoneChangeListener, ITicketChangeListener, TicketSystem
  )
-@@ -1097,6 +1097,389 @@
+@@ -1097,6 +1097,417 @@
          self.assertEqual([('Test', 0, 'Some text')], self.env.db_query(
              "SELECT name, time, description FROM version WHERE name='Test'"))
  
 +        self.action = []
 +
 +    def _handle(self, kwargs):
-+        cls = kwargs['entity'].__class__
-+        self.action.append(cls.__name__.lower() + '_' + kwargs['action'])
-+
-+        # Remove reference to self
-+        del kwargs['self']
 +        # Add action for custom events
 +        changeinfo = kwargs.get('changeinfo')
 +        if changeinfo is not None and changeinfo.action:
 +            kwargs['action'] = changeinfo.action
-+        # Add custom args and clear changeinfo
-+        kwargs.update(changeinfo.event_args or {}, changeinfo=None)
++        # Add custom args
++        kwargs.update(changeinfo.event_args or {})
++
++        # Remove reference to self and clear changeinfo
++        del kwargs['self']
++        del kwargs['changeinfo']
 +        self.details.append(kwargs)
 +
++        cls = kwargs['entity'].__class__
++        self.action.append(cls.__name__.lower() + '_' + kwargs['action'])
++
++
 +    def entity_created(self, entity, changeinfo=None):
 +        kwargs = locals()
 +        kwargs.update(action='created')
 +            def something_reparented(entity, changeinfo = None):
 +                """Never invoked. May be removed."""
 +
++            def something_reviewed(self, entity, seqnum, changeinfo=None):
++                """Custom event method"""
++
 +        class Something(object):
 +            def __init__(self, env):
 +                self.env = env
 +                                required_arg=self.required_arg,
 +                                **optional_args)
 +
++            def review(self, seqnum):
++                notifier = core.ListenerNotifier(self.env)
++                notifier.notify(ISomethingListener.something_reviewed,
++                                entity=self, seqnum=seqnum)
++
++
 +        class SomethingListener(core.Component):
 +            """Replicate the same behavior of generic listener
 +            """
 +                self.details = []
 +
 +            def _handle(self, kwargs):
-+                del kwargs['self']
 +                if 'optional_arg' in kwargs and kwargs['optional_arg'] is None:
 +                    del kwargs['optional_arg']
++                del kwargs['self']
++                del kwargs['changeinfo']
 +                self.details.append(kwargs)
 +
 +            def something_created(self, entity, changeinfo=None):
 +                args['action'] = 'reparented'
 +                self._handle(args)
 +
++            def something_reviewed(self, entity, seqnum, changeinfo=None):
++                args = locals()
++                args['action'] = 'reviewed'
++                self._handle(args)
++
 +        resource_listener = SomethingListener(self.env)
 +
 +        # CRUD operations
 +        something = Something(self.env)
 +        something.insert()
++        something.review(1)
 +        something.update()
 +        something.required_arg = 7
 +        something.optional_arg = 44
++        something.review(2)
 +        something.update()
 +        something.delete()
 +
 +        expected = [
 +                    {'action' : 'created',
 +                     'entity' : something,
-+                     'changeinfo' : None},
++                     },
++                    {'action' : 'reviewed',
++                     'entity' : something,
++                     'seqnum' : 1,
++                     },
 +                    {'action' : 'changed',
 +                     'entity' : something,
 +                     'old_values' : {},
 +                     'required_arg' : 999,
-+                     'changeinfo' : None},
++                     },
++                    {'action' : 'reviewed',
++                     'entity' : something,
++                     'seqnum' : 2,
++                     },
 +                    {'action' : 'changed',
 +                     'entity' : something,
 +                     'old_values' : {},
 +                     'required_arg' : 7,
 +                     'optional_arg' : 44,
-+                     'changeinfo' : None},
++                     },
 +                    {'action' : 'deleted',
 +                     'entity' : something,
-+                     'changeinfo' : None},
++                     },
 +                    ]
 +
 +        self.assertEquals(expected, self.listener.details,
  
  def suite():
      suite = unittest.TestSuite()
-@@ -1107,6 +1490,17 @@
+@@ -1107,6 +1518,17 @@
      suite.addTest(unittest.makeSuite(MilestoneTestCase, 'test'))
      suite.addTest(unittest.makeSuite(ComponentTestCase, 'test'))
      suite.addTest(unittest.makeSuite(VersionTestCase, 'test'))