[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests - testEventService.py:1.4

Gary Poster garyposter@earthlink.net
Thu, 5 Sep 2002 22:14:32 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests
In directory cvs.zope.org:/tmp/cvs-serv2358/tests

Modified Files:
	testEventService.py 
Log Message:
Fixed bug in LocalSubscribable and LocalServiceSubscribable (a 'self' should have been a 'wrapped_self').  Replaced the blah = blah persistence trick with _p_changed (as per discussion list) for these two files only.  Beautified two files hopefully as per style guide, or at least closer to it.  Wrote yet another event service test so we would have one that would have caught the bug (actually the test would only catch the bug in LocalServiceSubscribable, not LocalSubscribable--when something uses the LocalSubscribable mixin, it can test it.)


=== Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py:1.3	Thu Jul 11 14:21:31 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py	Thu Sep  5 22:14:31 2002
@@ -43,6 +43,7 @@
 from Zope.Event.ObjectEvent import ObjectAddedEvent
 from Zope.Event.GlobalEventService import GlobalEventService
 from Zope.Event.IEvent import IEvent
+from Zope.Event.ISubscriptionAware import ISubscriptionAware
 
 from EventSetup import EventSetup
 
@@ -60,6 +61,21 @@
 
     __implements__ = IObjectEvent
 
+
+
+class DummySubscriptionAwareSubscriber(DummySubscriber):
+    __implements__ = ISubscriptionAware
+    
+    def subscribedTo(self, subscribable, event_type, filter):
+        self.subscribable = subscribable
+        self.event_type = event_type
+        self.filter = filter
+    
+    def unsubscribedFrom(self, subscribable, event_type, filter):
+        self.un_subscribable = subscribable
+        self.un_event_type = event_type
+        self.un_filter = filter
+
 class EventServiceTests(EventSetup, TestCase):
     
     def _createNestedServices(self):
@@ -443,7 +459,43 @@
         directive = sm.getDirectives("Events")[0]
         sm.unbindService(directive) # make sure it doesn't raise any errors
         
-
+    def testSubscriptionAwareInteraction(self):
+        sub = DummySubscriptionAwareSubscriber()
+        self.rootFolder.setObject(
+            "mySubscriber",
+            DummySubscriptionAwareSubscriber())
+        self.mySubscriber=ContextWrapper(
+            self.rootFolder["mySubscriber"],
+            self.rootFolder,
+            name="mySubscriber")
+        filter = DummyFilter()
+        subscribe(
+            self.mySubscriber,
+            event_type=IObjectAddedEvent,
+            filter=filter)
+        self.assertEqual(
+            self.mySubscriber.subscribable,
+            self.rootFolder.getServiceManager().getService("Events"))
+        self.assertEqual(
+            self.mySubscriber.event_type,
+            IObjectAddedEvent)
+        self.assertEqual(
+            self.mySubscriber.filter,
+            filter)
+        unsubscribe(
+            self.mySubscriber,
+            event_type=IObjectAddedEvent,
+            filter=filter)
+        self.assertEqual(
+            self.mySubscriber.un_subscribable,
+            self.rootFolder.getServiceManager().getService("Events"))
+        self.assertEqual(
+            self.mySubscriber.un_event_type,
+            IObjectAddedEvent)
+        self.assertEqual(
+            self.mySubscriber.un_filter,
+            filter)
+        
         
 def test_suite():
     loader=TestLoader()