[Zope-Checkins] CVS: Zope3/lib/python/Zope/ObjectHub/tests - testObjectHub.py:1.1.2.5
Steve Alexander
steve@cat-box.net
Fri, 1 Mar 2002 11:08:43 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ObjectHub/tests
In directory cvs.zope.org:/tmp/cvs-serv694/lib/python/Zope/ObjectHub/tests
Modified Files:
Tag: Zope-3x-branch
testObjectHub.py
Log Message:
Changed ObjectRemovedEvent to take an object, as well as the location, as a
payload.
Here's a use-case:
> I want to make a subscriber that listens
> to object events to tell me the full name of contacts that get removed.
>
> To do this currently, I need to store the full name of each contact that
> gets created.
>
> If the object were passed with objectremoved events, I could just ask
> the object.
=== Zope3/lib/python/Zope/ObjectHub/tests/testObjectHub.py 1.1.2.4 => 1.1.2.5 ===
for spec,event in zip(event_spec_list, self.events_received):
- interface,ruid,location = spec
+ if len(spec)==4:
+ interface,ruid,location,obj = spec
+ else:
+ interface,ruid,location = spec
+ obj = None
location = self._canonical(location)
testcase.assert_(interface.isImplementedBy(event))
testcase.assertEqual(event.getLocation(), location)
+ if obj is not None:
+ testcase.assertEqual(event.getObject(), obj)
+
# Sometimes, the test won't care about the ruid. In this case,
# it is passed into the spec as None.
if ruid is not None:
@@ -75,12 +82,13 @@
class BasicHubTest(unittest.TestCase):
location = '/foo/bar'
+ obj = object()
new_location = '/baz/spoo'
def setUp(self):
self.added_event = ObjectAddedEvent(self.location)
self.added_new_location_event = ObjectAddedEvent(self.new_location)
- self.removed_event = ObjectRemovedEvent(self.location)
+ self.removed_event = ObjectRemovedEvent(self.location, self.obj)
self.modified_event = ObjectModifiedEvent(self.location)
self.moved_event = ObjectMovedEvent(self.location,
self.new_location)
@@ -162,6 +170,7 @@
added_event = self.added_event
removed_event = self.removed_event
location = self.location
+ obj = self.obj
hub.notify(added_event)
@@ -177,7 +186,7 @@
self.subscriber.verifyEventsReceived(self, [
(IRuidObjectAddedEvent, ruid, location),
- (IRuidObjectRemovedEvent, ruid, location)
+ (IRuidObjectRemovedEvent, ruid, location, obj)
])