[Zope-Checkins] CVS: Zope3/lib/python/Zope/Event/tests - testDirectives.py:1.1.2.4 testEventService.py:1.1.2.5 testLogger.py:1.1.2.3

Gary Poster garyposter@earthlink.net
Mon, 22 Apr 2002 15:03:25 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	testDirectives.py testEventService.py testLogger.py 
Log Message:
1. As per ZopeTop discussion, moved Addable out of ZMI into the Services folder, and turned it into a true service (this involved a lot of small changes, particularly in the folders and a number of tests) and gave it some hooks
2. used SteveA's ContextWrapper.ContextMethod to make the ServiceManager and Services placefully look up to parent placeful equivalents
3. Made Event into a more standard service, and gave it some hooks
4. Built the beginning of a placeful EventService (will need tests, and views, and EventChannels, and more meat; just wanted to check this in for now)
5. made it so you can't add an item to a folder with a blank string id, and updated the folder interface
6. some typos fixed here and there
7. a few more tests here and there

I'm checking this in then checking it out again to check my work; also tagged previous version as gary-service_update.



=== Zope3/lib/python/Zope/Event/tests/testDirectives.py 1.1.2.3 => 1.1.2.4 ===
 class Test(CleanUp, TestCase):
 
+    def getService_hook(self, context, name):
+        if name != "EventService" or context is not None: raise NotFoundError
+        return self.eventService
+    
+    def setUp(self):
+        from Zope.ComponentArchitecture import hooks
+        self.__old_getService_hook=hooks.getService_hook
+        hooks.getService_hook=self.getService_hook
+        from Zope.Event.EventService import EventService
+        self.eventService=EventService()
+    
+    def tearDown(self):
+        from Zope.ComponentArchitecture import hooks
+        hooks.getService_hook=self.__old_getService_hook
+
     def testSubscribe(self):
         from Zope.Event.tests.subscriber import subscriber
         # This should fail, since we're not subscribed
-        self.assertRaises(NotFoundError,unsubscribe,subscriber)
+        self.assertRaises(NotFoundError,unsubscribe,None,subscriber)
             
         xmlconfig(StringIO(template % (
             """
@@ -55,17 +70,17 @@
                              filter="Zope.Event.tests.subscriber.filter"/>
             """)))
 
-        publishEvent(ObjectAddedEvent('foo'))
+        publishEvent(None,ObjectAddedEvent('foo'))
         self.assertEqual(subscriber.notified,1)
-        publishEvent(ObjectRemovedEvent('foo', object()))
+        publishEvent(None,ObjectRemovedEvent('foo', object()))
         self.assertEqual(subscriber.notified,2)
-        publishEvent(ObjectModifiedEvent('foo'))
+        publishEvent(None,ObjectModifiedEvent('foo'))
         self.assertEqual(subscriber.notified,2) # NB: no increase ;-)
-        publishEvent(DummyEvent())
+        publishEvent(None,DummyEvent())
         self.assertEqual(subscriber.notified,4) # NB: increased by 2 ;-)
         
         # This should not fail, since we should be subscribed by now ;-)
-        unsubscribe(subscriber)
+        unsubscribe(None,subscriber)
 
 def test_suite():
     return TestSuite((


=== Zope3/lib/python/Zope/Event/tests/testEventService.py 1.1.2.4 => 1.1.2.5 ===
 from Zope.Event.EventService import EventService
 from Zope.Exceptions import NotFoundError
-from Zope import Event
+#from Zope import Event
 
 from subscriber import DummySubscriber, DummyFilter
 
@@ -215,19 +215,11 @@
             event_types=[IObjectAddedEvent],
             )
         self.service.publishEvent(ObjectEvent())
-        self.assertEqual(self.subscriber.notified, 1)        
-
-class TestFSEventService(CleanUp, TestEventService):
-  
-    def setUp(self):
-        self.service = Event
-        self.event = ObjectAddedEvent('/foo')
-        self.subscriber = DummySubscriber()
+        self.assertEqual(self.subscriber.notified, 1)
     
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestEventService),
-        unittest.makeSuite(TestFSEventService),
         ))
 
 if __name__=='__main__':


=== Zope3/lib/python/Zope/Event/tests/testLogger.py 1.1.2.2 => 1.1.2.3 ===
 from zLOG import BLATHER, PANIC
 
+from Zope.Event.EventService import EventService
+
 class DopeyLogger:
 
     def __init__(self):
@@ -37,19 +39,28 @@
         
 class TestLogger1(CleanUp,unittest.TestCase):
 
+    def dummyGetService(self, *ignore1, **ignore2):
+        return self.eventService
+
     eventlogger = Logger()
 
     def setUp(self):
+        from Zope.ComponentArchitecture import hooks
+        self.__old_getService_hook=hooks.getService_hook
+        hooks.getService_hook=self.dummyGetService
+        self.eventService=EventService()
         # futz a logger in for testing
         self.__old_log_write = zLOG.log_write
         self.logger = DopeyLogger()
         zLOG.log_write = self.logger.log_write
         # register a logger
-        subscribe(self.eventlogger)
+        subscribe(None, self.eventlogger)
         # send an event
-        publishEvent(ObjectAddedEvent('foo'))
+        publishEvent(None, ObjectAddedEvent('foo'))
 
     def tearDown(self):
+        from Zope.ComponentArchitecture import hooks
+        hooks.getService_hook=self.__old_getService_hook
         #unsubscribe(self.eventlogger)
         zLOG.log_write = self.__old_log_write
         CleanUp.tearDown(self)