[Zope-Checkins] CVS: Zope3/lib/python/Zope/ObjectHub/tests - testObjectHub.py:1.4

Holger Krekel hpk@devel.trillke.net
Tue, 25 Jun 2002 06:45:46 -0400


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

Modified Files:
	testObjectHub.py 
Log Message:
- added register/unregister methods to IObjectHub and its default
  implementation. 

- testObjectHub checks for correct Register/Unregister Events
  and errors

Godefroid and Holger



=== Zope3/lib/python/Zope/ObjectHub/tests/testObjectHub.py 1.3 => 1.4 ===
 import Zope.ObjectHub.RuidObjectEvent as RuidObjectEvent
 
-#from  Zope.ObjectHub.RuidObjectEvent import RuidObjectRegisteredEvent
-#from  Zope.ObjectHub.RuidObjectEvent import RuidObjectAddedEvent
-#from  Zope.ObjectHub.RuidObjectEvent import RuidObjectUnregisteredEvent
-#from  Zope.ObjectHub.RuidObjectEvent import RuidObjectModifiedEvent
-#from  Zope.ObjectHub.RuidObjectEvent import RuidObjectContextChangedEvent
-#from  Zope.ObjectHub.RuidObjectEvent import RuidObjectRemovedEvent
-
 from Zope.Exceptions import NotFoundError
 from types import StringTypes
 
@@ -88,6 +81,8 @@
             # it is passed into the spec as None.
             if ruid is not None:
                 testcase.assertEqual(event.getRuid(), ruid)
+
+        self.events_received=[]
   
 class TransmitRuidObjectEventTest(unittest.TestCase):
     ruid = 23
@@ -156,7 +151,35 @@
 
         # TODO: test that ObjectHub acts as an EventChannel
 
+class TestRegistrationEvents(BasicHubTest):
+    def testRegistration(self):
+        # check for notFoundError
+        self.assertRaises(NotFoundError,  self.object_hub.unregister, self.location)
+        self.assertRaises(NotFoundError,  self.object_hub.unregister, 42)
+
+        ruid = self.object_hub.register(self.location)
+        ruid2 = self.object_hub.register(self.new_location)
+
+        self.subscriber.verifyEventsReceived(self, [
+                (IRuidObjectRegisteredEvent, ruid, self.location),
+                (IRuidObjectRegisteredEvent, ruid2, self.new_location)
+            ])
+
+        # register again and check for error
+        self.assertRaises(ObjectHubError,  self.object_hub.register, self.location)
 
+        # unregister first object by location
+        self.object_hub.unregister(self.location)
+        self.subscriber.verifyEventsReceived(self, [
+                (IRuidObjectUnregisteredEvent, ruid, self.location)
+            ])
+        # unregister second object by ruid
+        self.object_hub.unregister(ruid2)
+        self.subscriber.verifyEventsReceived(self, [
+                (IRuidObjectUnregisteredEvent, ruid2, self.new_location)
+            ])
+
+        
 class TestObjectAddedEvent(BasicHubTest):
             
     def testLookingUpLocation(self):
@@ -396,6 +419,7 @@
         unittest.makeSuite(TransmitRuidObjectContextChangedEventTest),
         unittest.makeSuite(TransmitRuidObjectRegisteredEventTest),
         unittest.makeSuite(TransmitRuidObjectUnregisteredEventTest),
+        unittest.makeSuite(TestRegistrationEvents),
         ))
 
 if __name__=='__main__':