[Zope-Checkins] CVS: Zope3/lib/python/Zope/Event/tests - testEventService.py:1.1.2.8

Gary Poster garyposter@earthlink.net
Fri, 17 May 2002 23:32:50 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Event/tests
In directory cvs.zope.org:/tmp/cvs-serv19452/lib/python/Zope/Event/tests

Modified Files:
      Tag: Zope-3x-branch
	testEventService.py 
Log Message:
Some tests of the changes in the global event service, and a small fix that one of them found.  Tests of the local event service later...



=== Zope3/lib/python/Zope/Event/tests/testEventService.py 1.1.2.7 => 1.1.2.8 ===
 from Zope.Event.IObjectEvent import IObjectRemovedEvent
 from Zope.Event.IObjectEvent import IObjectModifiedEvent
-from Zope.Event.ObjectEvent import ObjectAddedEvent
+from Zope.Event.ObjectEvent import ObjectAddedEvent, ObjectModifiedEvent
 from Zope.Event.GlobalEventService import GlobalEventService
 from Zope.Exceptions import NotFoundError
+from Zope.Event.IEvent import IEvent
 
 from subscriber import DummySubscriber, DummyFilter
 
@@ -163,6 +164,50 @@
                           subscriber, IObjectEvent)
         self.assertEqual(None,
                          self.service.unsubscribe(subscriber))
+    
+    def testUnsubscribe3(self):
+        "Test selective unsubscribe"
+        subscriber2=DummySubscriber()
+        filter=DummyFilter()
+        event2=ObjectModifiedEvent('/foo')
+        self.service.subscribe(
+            self.subscriber)
+        self.service.subscribe(
+            self.subscriber,
+            event_type=IObjectAddedEvent,
+            filter=filter
+            )
+        self.service.subscribe(
+            self.subscriber,
+            event_type=IObjectAddedEvent
+            )
+        self.service.subscribe(
+            subscriber2,
+            event_type=IObjectAddedEvent
+            )
+        self.service.publishEvent(self.event)
+        self.assertEqual(self.subscriber.notified, 3)
+        self.assertEqual(subscriber2.notified, 1)
+        self.service.publishEvent(event2)
+        self.assertEqual(self.subscriber.notified, 4)
+        self.assertEqual(subscriber2.notified, 1)
+        self.service.unsubscribe(self.subscriber, IObjectAddedEvent)
+        self.service.publishEvent(self.event)
+        self.assertEqual(self.subscriber.notified, 6)
+        self.assertEqual(subscriber2.notified, 2)
+        self.service.unsubscribe(self.subscriber, IEvent)
+        self.service.publishEvent(event2)
+        self.assertEqual(self.subscriber.notified, 6)
+        self.assertEqual(subscriber2.notified, 2)
+        self.assertRaises(NotFoundError, self.service.unsubscribe, self.subscriber, IObjectAddedEvent)
+        self.service.unsubscribe(self.subscriber, IObjectAddedEvent, filter)
+        self.service.publishEvent(self.event)
+        self.assertEqual(self.subscriber.notified, 6)
+        self.assertEqual(subscriber2.notified, 3)
+        self.service.unsubscribe(subscriber2, IObjectAddedEvent)
+        self.service.publishEvent(self.event)
+        self.assertEqual(self.subscriber.notified, 6)
+        self.assertEqual(subscriber2.notified, 3)
 
     def testpublishEvent1(self):
         "Test publishEvent method"
@@ -222,6 +267,26 @@
             )
         self.service.publishEvent(ObjectEvent())
         self.assertEqual(self.subscriber.notified, 1)
+    
+    def testListSubscriptions1(self):
+        "a non-subscribed subscriber gets an empty array"
+        self.assertEqual([], self.service.listSubscriptions(self.subscriber))
+    
+    def testListSubscriptions2(self):
+        "one subscription"
+        self.service.subscribe(
+            self.subscriber,
+            event_type=IObjectAddedEvent
+            )
+        self.assertEqual([(IObjectAddedEvent,None)], self.service.listSubscriptions(self.subscriber))
+    
+    def testListSubscriptions3(self):
+        "listing limited subscription"
+        self.service.subscribe(
+            self.subscriber,
+            event_type=IObjectAddedEvent
+            )
+        self.assertEqual([], self.service.listSubscriptions(self.subscriber, IObjectRemovedEvent))
     
 def test_suite():
     return unittest.TestSuite((