[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests - testEventService.py:1.1.2.4
Gary Poster
garyposter@earthlink.net
Sun, 19 May 2002 13:43:31 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests
In directory cvs.zope.org:/tmp/cvs-serv8180/lib/python/Zope/App/OFS/Services/LocalEventService/tests
Modified Files:
Tag: Zope-3x-branch
testEventService.py
Log Message:
more tests and fixes to the local event service
=== Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py 1.1.2.3 => 1.1.2.4 ===
self.assertEqual(subscriber.notified, 1)
- def testNonPromotingEventService1(self):
- """test to see if events are not passed on to a parent event
- service with the appropriate isPromotableEvent setting"""
+ def _createAlternateService(self, service):
self._createSubscribers()
self.folder2.setObject("folder2Subscriber", DummySubscriber())
self.folder2Subscriber=ContextWrapper(
@@ -368,7 +366,7 @@
if not self.folder2.hasServiceManager():
self.createServiceManager(self.folder2)
sm=getServiceManager(self.folder2) # wrapped now
- sm.setObject("myEventService",UnpromotingLocalEventService()) # this is the change
+ sm.setObject("myEventService",service) # this is the change
sm.bindService("Events","myEventService")
subscribe(
self.rootFolderSubscriber,
@@ -378,35 +376,57 @@
self.folder2Subscriber,
event_type=IObjectAddedEvent
)
+
+ def testNonPromotingEventService1(self):
+ """test to see if events are not passed on to a parent event
+ service with the appropriate isPromotableEvent setting"""
+ self._createAlternateService(UnpromotingLocalEventService())
publishEvent(self.folder2, ObjectAddedEvent('/foo'))
self.assertEqual(self.folder2Subscriber.notified, 1)
self.assertEqual(self.rootFolderSubscriber.notified, 0)
def testPromotingEventService1(self):
- """test to see if events are not passed on to a parent event
+ """test to see if events are passed on to a parent event
service with the appropriate isPromotableEvent setting"""
+ self._createAlternateService(LocalEventService())
+ publishEvent(self.folder2, ObjectAddedEvent('/foo'))
+ self.assertEqual(self.folder2Subscriber.notified, 1)
+ self.assertEqual(self.rootFolderSubscriber.notified, 1)
+
+ def testUnbindingResubscribing1(self):
+ """an event service is unbound; a lower event service should
+ then rebind to upper event service"""
+ self._createNestedServices()
self._createSubscribers()
- self.folder2.setObject("folder2Subscriber", DummySubscriber())
- self.folder2Subscriber=ContextWrapper(
- self.folder2.getObject("folder2Subscriber"),
- self.folder2,
- name="folder2Subscriber")
- if not self.folder2.hasServiceManager():
- self.createServiceManager(self.folder2)
- sm=getServiceManager(self.folder2) # wrapped now
- sm.setObject("myEventService",LocalEventService()) # this is the change
- sm.bindService("Events","myEventService")
subscribe(
self.rootFolderSubscriber,
event_type=IObjectAddedEvent
)
subscribe(
- self.folder2Subscriber,
+ self.folder1Subscriber,
event_type=IObjectAddedEvent
)
- publishEvent(self.folder2, ObjectAddedEvent('/foo'))
- self.assertEqual(self.folder2Subscriber.notified, 1)
+ subscribe(
+ self.folder1_1Subscriber,
+ event_type=IObjectAddedEvent
+ )
+ sm=getServiceManager(self.folder1)
+ sm.unbindService("Events")
+ publishEvent(self.rootFolder, ObjectAddedEvent('/foo'))
+ self.assertEqual(self.folder1Subscriber.notified, 0)
+ self.assertEqual(self.folder1_1Subscriber.notified, 1)
+
+ def testNoSubscribeOnBind(self):
+ """if subscribeOnBind is 0, service should not subscribe to
+ parent"""
+ sv=LocalEventService()
+ sv.subscribeOnBind=0
+ self._createAlternateService(sv)
+ publishEvent(self.rootFolder, ObjectAddedEvent('/foo'))
+ self.assertEqual(self.folder2Subscriber.notified, 0)
self.assertEqual(self.rootFolderSubscriber.notified, 1)
+ sm=getServiceManager(self.folder2)
+ sm.unbindService("Events") # make sure it doesn't raise any errors