[Zope3-checkins] CVS: Zope3/lib/python/Zope/ObjectHub/tests - testHubEvent.py:1.3 testObjectHub.py:1.9

Gary Poster gary@modernsongs.com
Mon, 21 Oct 2002 02:14:49 -0400


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

Modified Files:
	testHubEvent.py testObjectHub.py 
Log Message:
sorry for the huge honking checkin.

Adds a simple local objecthub implementation and made ObjectHub a service

Modifies the main objecthub as we have been discussing:
 * objecthub attribute is hubid, not hid (sorry Jim, I'll change it back if you want but there were a lot of "yay"s and no "nay"s :-)
 * no more IObjectAddedHubEvent
 * IObjectRemovedEvent now (hopefully) actually has the effect on the ObjectHub that is described in the interface, and that we agreed upon, namely (assuming removed object was cataloged in objecthub) removing catalog of object in objecthub and sending out an IObjectRemovedHubEvent, subclass of IObjectUnregisteredHubEvent, to the ObjectHub subscribers

I tried to spruce up the LocalEventService a bit but the code still looks as opaque as ever, I'm afraid.  Among other small improvements, though, at least you actually can see the silly "user interface" now without a traceback.  Now for a *real* user interface sometime. :-)

Fixed a few typos while I was at it as well...and I'm sure made my share of new ones :-)




=== Zope3/lib/python/Zope/ObjectHub/tests/testHubEvent.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/ObjectHub/tests/testHubEvent.py:1.2	Thu Oct  3 16:53:23 2002
+++ Zope3/lib/python/Zope/ObjectHub/tests/testHubEvent.py	Mon Oct 21 02:14:48 2002
@@ -21,7 +21,6 @@
 
 from Zope.ObjectHub.HubEvent import ObjectRegisteredHubEvent
 from Zope.ObjectHub.HubEvent import ObjectUnregisteredHubEvent
-from Zope.ObjectHub.HubEvent import ObjectAddedHubEvent
 from Zope.ObjectHub.HubEvent import ObjectModifiedHubEvent
 from Zope.ObjectHub.HubEvent import ObjectMovedHubEvent
 from Zope.ObjectHub.HubEvent import ObjectRemovedHubEvent
@@ -41,54 +40,55 @@
             
         raise NotFoundError
         
-class TestObjectAddedHubEvent(unittest.TestCase):
+class AbstractTestHubEvent(unittest.TestCase):
     
     location = '/some/location'
-    ruid = 23
+    hubid = 23
     obj = object()
-    klass = ObjectAddedHubEvent
+    klass = None
     
     def setUp(self):
-        objecthub = DummyObjectHub(self.ruid, self.obj)
-        self.event = self.klass(objecthub, self.ruid, self.location)
+        objecthub = DummyObjectHub(self.hubid, self.obj)
+        self.event = self.klass(objecthub, self.hubid, self.location)
         
     def testGetLocation(self):
         self.assertEqual(self.event.location, self.location)
         
-    def testGetRuid(self):
-        self.assertEqual(self.event.hid, self.ruid)
+    def testGetHubId(self):
+        "Test hubid"
+        self.assertEqual(self.event.hubid, self.hubid)
     
     def testGetObject(self):
         self.assertEqual(self.event.object, self.obj)
     
-class TestObjectRegisteredHubEvent(TestObjectAddedHubEvent):
+class TestObjectRegisteredHubEvent(AbstractTestHubEvent):
 
     klass = ObjectRegisteredHubEvent
 
-class TestObjectUnregisteredHubEvent(TestObjectAddedHubEvent):
+class TestObjectUnregisteredHubEvent(AbstractTestHubEvent):
 
     klass = ObjectUnregisteredHubEvent
 
-class TestObjectModifiedHubEvent(TestObjectAddedHubEvent):
+class TestObjectModifiedHubEvent(AbstractTestHubEvent):
 
     klass = ObjectModifiedHubEvent
 
-class TestObjectMovedHubEvent(TestObjectAddedHubEvent):
+class TestObjectMovedHubEvent(AbstractTestHubEvent):
 
     klass = ObjectMovedHubEvent
 
-class TestObjectRemovedHubEvent(TestObjectAddedHubEvent):
+class TestObjectRemovedHubEvent(AbstractTestHubEvent):
 
     klass = ObjectRemovedHubEvent
 
     def setUp(self):
-        self.event = self.klass(self.obj, self.ruid, self.location)
+        AbstractTestHubEvent.setUp(self)
+        self.event = self.klass(self.obj, self.hubid, self.location)
 
 
 
 def test_suite():
     return unittest.TestSuite((
-        unittest.makeSuite(TestObjectAddedHubEvent),
         unittest.makeSuite(TestObjectRegisteredHubEvent),
         unittest.makeSuite(TestObjectUnregisteredHubEvent),
         unittest.makeSuite(TestObjectModifiedHubEvent),


=== Zope3/lib/python/Zope/ObjectHub/tests/testObjectHub.py 1.8 => 1.9 ===
--- Zope3/lib/python/Zope/ObjectHub/tests/testObjectHub.py:1.8	Thu Oct  3 16:53:23 2002
+++ Zope3/lib/python/Zope/ObjectHub/tests/testObjectHub.py	Mon Oct 21 02:14:48 2002
@@ -26,14 +26,13 @@
 from Zope.Event.ISubscriber import ISubscriber
 
 from Zope.ObjectHub.ObjectHub import ObjectHub, ObjectHubError
-from Zope.ObjectHub.IHubEvent import IObjectAddedHubEvent
 from Zope.ObjectHub.IHubEvent import IObjectRemovedHubEvent
 from Zope.ObjectHub.IHubEvent import IObjectModifiedHubEvent
 from Zope.ObjectHub.IHubEvent import IObjectMovedHubEvent
 from Zope.ObjectHub.IHubEvent import IObjectRegisteredHubEvent
 from Zope.ObjectHub.IHubEvent import IObjectUnregisteredHubEvent
 
-import Zope.ObjectHub.HubEvent as RuidObjectEvent
+import Zope.ObjectHub.HubEvent as HubIdObjectEvent
 
 from Zope.Exceptions import NotFoundError
 from types import StringTypes
@@ -59,20 +58,20 @@
     def verifyEventsReceived(self, testcase, event_spec_list):
         # iterate through self.events_received and check
         # that each one implements the interface that is
-        # in the same place, with the same location and ruid
+        # in the same place, with the same location and hub id
         
         testcase.assertEqual(len(event_spec_list), len(self.events_received))
         
         for spec,event in zip(event_spec_list, self.events_received):
             if len(spec)==4:
-                interface,ruid,location,obj = spec
+                interface,hubid,location,obj = spec
             elif len(spec)==3:
-                interface,ruid,location = spec
+                interface,hubid,location = spec
                 obj = None
             elif len(spec)==2:
                 interface, location = spec
                 obj = None
-                ruid = None
+                hubid = None
             location = self._canonical(location)
             testcase.assert_(interface.isImplementedBy(event),
                              'Interface %s' % interface.getName())
@@ -81,10 +80,10 @@
             if obj is not None:
                 testcase.assertEqual(event.object, obj)
             
-            # Sometimes, the test won't care about the ruid. In this case,
+            # Sometimes, the test won't care about the hubid. In this case,
             # it is passed into the spec as None.
-            if ruid is not None:
-                testcase.assertEqual(event.hid, ruid)
+            if hubid is not None:
+                testcase.assertEqual(event.hubid, hubid)
 
         self.events_received = []
 
@@ -92,28 +91,16 @@
     def __init__(self, objectHub):
         LoggingSubscriber.__init__(self)
         self.hub = objectHub
-	
+
     def notify(self, event):
         LoggingSubscriber.notify(self, event)
         if IObjectAddedEvent.isImplementedBy(event):
-            self.hub.register(event.location)                  
-        elif IObjectRemovedEvent.isImplementedBy(event):
-            try:
-                ruid = self.hub.lookupRuid(event.location)
-            except NotFoundError:
-                pass
-            else:   
-                location = event.location
-                obj = event.object
-                removeEvent = RuidObjectEvent.ObjectRemovedHubEvent(
-                    obj, ruid, location)
-                self.hub.notify(removeEvent)
-                self.hub.unregister(location)                  
+            self.hub.register(event.location)  
 
 class TransmitHubEventTest(unittest.TestCase):
-    ruid = 23
+    hubid = 23
     location = '/foo/bar'
-    # Don't test the HubtEvent base class.
+    # Don't test the HubEvent base class.
     # See below for testing subclasses / subinterfaces
     # klass = HubEvent
     # interface = IHubEvent
@@ -121,7 +108,7 @@
     def setUp(self):
         self.object_hub = ObjectHub()
         self.hub_event = self.klass(self.object_hub,
-                                           self.ruid, 
+                                           self.hubid, 
                                            self.location)
 
         self.subscriber = LoggingSubscriber()
@@ -133,32 +120,28 @@
         self.object_hub.notify(self.hub_event)
        
         self.subscriber.verifyEventsReceived(self, [
-                (self.interface, self.ruid, self.location)
+                (self.interface, self.hubid, self.location)
             ])
-   
-class TransmitObjectAddedHubEventTest(TransmitHubEventTest):
-    interface = IObjectAddedHubEvent
-    klass = RuidObjectEvent.ObjectAddedHubEvent
 
 class TransmitObjectRemovedHubEventTest(TransmitHubEventTest):
     interface = IObjectRemovedHubEvent
-    klass = RuidObjectEvent.ObjectRemovedHubEvent
+    klass = HubIdObjectEvent.ObjectRemovedHubEvent
 
 class TransmitObjectModifiedHubEventTest(TransmitHubEventTest):
     interface = IObjectModifiedHubEvent
-    klass = RuidObjectEvent.ObjectModifiedHubEvent
+    klass = HubIdObjectEvent.ObjectModifiedHubEvent
 
 class TransmitObjectMovedHubEventTest(TransmitHubEventTest):
     interface = IObjectMovedHubEvent
-    klass = RuidObjectEvent.ObjectMovedHubEvent
+    klass = HubIdObjectEvent.ObjectMovedHubEvent
 
 class TransmitObjectRegisteredHubEventTest(TransmitHubEventTest):
     interface = IObjectRegisteredHubEvent
-    klass = RuidObjectEvent.ObjectRegisteredHubEvent
+    klass = HubIdObjectEvent.ObjectRegisteredHubEvent
 
 class TransmitObjectUnregisteredHubEventTest(TransmitHubEventTest):
     interface = IObjectUnregisteredHubEvent
-    klass = RuidObjectEvent.ObjectUnregisteredHubEvent
+    klass = HubIdObjectEvent.ObjectUnregisteredHubEvent
     
 class BasicHubTest(unittest.TestCase):
 
@@ -189,12 +172,12 @@
                           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)
+        hubid = self.object_hub.register(self.location)
+        hubid2 = self.object_hub.register(self.new_location)
 
         self.subscriber.verifyEventsReceived(self, [
-                (IObjectRegisteredHubEvent, ruid, self.location),
-                (IObjectRegisteredHubEvent, ruid2, self.new_location)
+                (IObjectRegisteredHubEvent, hubid, self.location),
+                (IObjectRegisteredHubEvent, hubid2, self.new_location)
             ])
 
         # register again and check for error
@@ -205,12 +188,13 @@
         # unregister first object by location
         self.object_hub.unregister(self.location)
         self.subscriber.verifyEventsReceived(self, [
-                (IObjectUnregisteredHubEvent, ruid, self.location)
+                (IObjectUnregisteredHubEvent, hubid, self.location)
             ])
-        # unregister second object by ruid
-        self.object_hub.unregister(ruid2)
+
+        # unregister second object by hub id
+        self.object_hub.unregister(hubid2)
         self.subscriber.verifyEventsReceived(self, [
-                (IObjectUnregisteredHubEvent, ruid2, self.new_location)
+                (IObjectUnregisteredHubEvent, hubid2, self.new_location)
             ])
 
     def testRegistrationRelativeLocation(self):
@@ -220,7 +204,7 @@
 class TestNoRegistration(BasicHubTest):
             
     def testAddWithoutRegistration(self):
-        """Test that no RuidEvents are generated
+        """Test that no HubIdEvents are generated
         
         if there is no registration
         """
@@ -245,7 +229,7 @@
     def testLookingUpLocation(self):
         """Test that the location is in the lookup
         
-        Compare getRuidForLocation and getLocationForRuid
+        Compare getHubIdForLocation and getLocationForHubId
 
         Checks the sequence of events
         
@@ -256,23 +240,22 @@
         
         hub.notify(event)
         
-        ruid = hub.lookupRuid(location)
-        # check that ruid is an int
-        int(ruid)
+        hubid = hub.lookupHubId(location)
+        # check that hub id is an int
+        self.failUnless(isinstance(hubid, int)) # int(hubid)
         
-        location_from_hub = hub.lookupLocation(ruid)
+        location_from_hub = hub.lookupLocation(hubid)
 
         self.assertEqual(location_from_hub, location)
         
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectAddedEvent, location),
-                (IObjectRegisteredHubEvent, ruid, location),
-                (IObjectAddedHubEvent, ruid, location),
+                (IObjectRegisteredHubEvent, hubid, location),
             ])
 
         
     def testLookupUpAbsentLocation(self):
-        """Test that we don't find an ruid for location
+        """Test that we don't find an hub id for location
            that we haven't added.
         """
         hub = self.object_hub
@@ -282,14 +265,14 @@
         # Do not add the location to the hub
         # hub.notify(event)
         
-        self.assertRaises(NotFoundError, hub.lookupRuid, location)
+        self.assertRaises(NotFoundError, hub.lookupHubId, location)
 
         self.subscriber.verifyEventsReceived(self, [])
 
 
         
-    def testLookupUpAbsentRuid(self):
-        """Test that we don't find a location for an ruid
+    def testLookupUpAbsentHubId(self):
+        """Test that we don't find a location for an hub id
            that isn't there.
         """
         hub = self.object_hub
@@ -298,9 +281,9 @@
         # Do not add the location to the hub
         # hub.notify(event)
         
-        absent_ruid = 12
+        absent_hubid = 12
         
-        self.assertRaises(NotFoundError, hub.lookupLocation, absent_ruid)
+        self.assertRaises(NotFoundError, hub.lookupLocation, absent_hubid)
         
         self.subscriber.verifyEventsReceived(self, [])
 
@@ -326,23 +309,21 @@
         
         hub.notify(added_event)
         
-        ruid = hub.lookupRuid(location)
+        hubid = hub.lookupHubId(location)
         
-        # check that ruid is an int
-        int(ruid)
+        # check that hubid is an int
+        self.failUnless(isinstance(hubid, int)) # int(hubid)
         
         hub.notify(removed_event)
         
-        self.assertRaises(NotFoundError, hub.lookupRuid, location)
-        self.assertRaises(NotFoundError, hub.lookupLocation, ruid)
+        self.assertRaises(NotFoundError, hub.lookupHubId, location)
+        self.assertRaises(NotFoundError, hub.lookupLocation, hubid)
         
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectAddedEvent, location),
-                (IObjectRegisteredHubEvent, ruid, location),
-                (IObjectAddedHubEvent, ruid, location),
+                (IObjectRegisteredHubEvent, hubid, location),
                 (IObjectRemovedEvent, location),
-                (IObjectRemovedHubEvent, ruid, location, obj),
-                (IObjectUnregisteredHubEvent, ruid, location),
+                (IObjectRemovedHubEvent, hubid, location, obj),
             ])
         
         
@@ -382,27 +363,26 @@
         
         hub.notify(added_event)
         
-        ruid = hub.lookupRuid(location)
-        # check that ruid is an int
-        int(ruid)
+        hubid = hub.lookupHubId(location)
+        # check that hubid is an int
+        self.failUnless(isinstance(hubid, int)) # int(hubid)
         
-        location_from_hub = hub.lookupLocation(ruid)
+        location_from_hub = hub.lookupLocation(hubid)
         self.assertEqual(location_from_hub, location)
         
         hub.notify(modified_event)
         
-        ruid2 = hub.lookupRuid(location)
-        location_from_hub2 = hub.lookupLocation(ruid2)
+        hubid2 = hub.lookupHubId(location)
+        location_from_hub2 = hub.lookupLocation(hubid2)
         
         self.assertEqual(location_from_hub, location_from_hub2)
-        self.assertEqual(ruid, ruid2)
+        self.assertEqual(hubid, hubid2)
         
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectAddedEvent, location),
-                (IObjectRegisteredHubEvent, ruid, location),
-                (IObjectAddedHubEvent, ruid, location),
+                (IObjectRegisteredHubEvent, hubid, location),
                 (IObjectModifiedEvent, location),
-                (IObjectModifiedHubEvent, ruid, location)
+                (IObjectModifiedHubEvent, hubid, location)
             ])
 
         
@@ -420,7 +400,7 @@
         # hub.notify(added_event)
         
         hub.notify(modified_event)
-        self.assertRaises(NotFoundError, hub.lookupRuid, location)
+        self.assertRaises(NotFoundError, hub.lookupHubId, location)
         
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectModifiedEvent, location),
@@ -444,29 +424,28 @@
         new_location = self.new_location
         
         hub.notify(added_event)
-        ruid = hub.lookupRuid(location)
+        hubid = hub.lookupHubId(location)
         
         hub.notify(moved_event)
         
-        location_from_hub = hub.lookupLocation(ruid)
+        location_from_hub = hub.lookupLocation(hubid)
                 
         self.assertEqual(location_from_hub, new_location)
-        self.assertRaises(NotFoundError, hub.lookupRuid, location)
+        self.assertRaises(NotFoundError, hub.lookupHubId, location)
                 
-        ruid2 = hub.lookupRuid(new_location)
-        self.assertEqual(ruid2, ruid)
+        hubid2 = hub.lookupHubId(new_location)
+        self.assertEqual(hubid2, hubid)
         
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectAddedEvent, location),
-                (IObjectRegisteredHubEvent, ruid, location),
-                (IObjectAddedHubEvent, ruid, location),
+                (IObjectRegisteredHubEvent, hubid, location),
                 (IObjectMovedEvent, new_location),
-                (IObjectMovedHubEvent, ruid, new_location)
+                (IObjectMovedHubEvent, hubid, new_location)
             ])
 
 
     def testMovedAbsentLocation(self):
-        """Test that moving an absent location is a noop.
+        """Test that moving an absent location is a no-op.
         """
         hub = self.object_hub
         added_event = self.added_event
@@ -478,8 +457,8 @@
         # hub.notify(added_event)
         
         hub.notify(moved_event)
-        self.assertRaises(NotFoundError, hub.lookupRuid, location)
-        self.assertRaises(NotFoundError, hub.lookupRuid, new_location)
+        self.assertRaises(NotFoundError, hub.lookupHubId, location)
+        self.assertRaises(NotFoundError, hub.lookupHubId, new_location)
         
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectMovedEvent, new_location),
@@ -504,16 +483,13 @@
         self.subscriber.verifyEventsReceived(self, [
                 (IObjectAddedEvent, location),
                 (IObjectRegisteredHubEvent, None, location),
-                (IObjectAddedHubEvent, None, location),
                 (IObjectAddedEvent, new_location),
                 (IObjectRegisteredHubEvent, None, new_location),
-                (IObjectAddedHubEvent, None, new_location),
                 (IObjectMovedEvent, new_location),
             ])
         
 def test_suite():
     return unittest.TestSuite((
-        unittest.makeSuite(TransmitObjectAddedHubEventTest),
         unittest.makeSuite(TransmitObjectRemovedHubEventTest),
         unittest.makeSuite(TransmitObjectModifiedHubEventTest),
         unittest.makeSuite(TransmitObjectMovedHubEventTest),