def setUpEventListeners(self): """Install a listener for events emitted during the test.""" self.collected_events = [] if hasattr(self, 'modified_event_listener'): # Event listeners is already registered. return self.modified_event_listener = TestEventListener( IQuestion, IObjectModifiedEvent, self.collectEvent) self.created_event_listener = TestEventListener( IQuestionMessage, IObjectCreatedEvent, self.collectEvent)
def setUp(self): # Use an admin to get launchpad.Edit on all the branches to easily # approve and reject the proposals. super(TestCodeReviewKarma, self).setUp('*****@*****.**') # The way the zope infrastructure works is that we can register # subscribers easily, but there is no way to unregister them (bug # 2338). TestEventListener does this with by setting a property to # stop calling the callback function. Instead of ending up with a # whole pile of registered inactive event listeners, we just # reactivate the one we have if there is one. if self.karma_listener is None: self.karma_listener = TestEventListener(IPerson, IKarmaAssignedEvent, self._on_karma_assigned) else: self.karma_listener._active = True self.karma_events = []
def register_listener(self): """Register listener. Must be `unregister`ed later.""" self.listener = TestEventListener(IPerson, IKarmaAssignedEvent, self.receive)