[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_eventservice.py:1.6
Steve Alexander
steve@cat-box.net
Tue, 28 Jan 2003 06:30:59 -0500
Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv13119/src/zope/app/services/tests
Modified Files:
test_eventservice.py
Log Message:
Local event service now uses adapts to ISubscribingAware.
I changed loops of the form
for subs in something:
dosomething(subs[0])
dosomethingelse(subs[1])
to
for athing, anotherthing in something:
dosomething(athing)
dosomethingelse(anotherthing)
However, I don't understand what the 'anotherthing' should be in a couple
of places. I'll look into it further, or ask Gary for help.
Also, there are a couple of places where I'm not sure if the subscriber
object needs to be checked to see if it is None. I need to look into
those cases.
All unit tests pass, however.
=== Zope3/src/zope/app/services/tests/test_eventservice.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/services/tests/test_eventservice.py:1.5 Mon Jan 27 13:39:47 2003
+++ Zope3/src/zope/app/services/tests/test_eventservice.py Tue Jan 28 06:30:57 2003
@@ -39,6 +39,8 @@
from zope.app.interfaces.services.configuration import Registered
from zope.proxy.context import ContextWrapper
from zope.app.services.tests.eventsetup import EventSetup
+from zope.component.tests.components import RecordingAdapter
+from zope.component.adapter import provideAdapter
class UnpromotingEventService(EventService):
@@ -79,31 +81,30 @@
return i
raise NotFoundError
+class IHasSubscribingAwareAdapter(Interface):
+ pass
-class DummySubscriptionAwareSubscriber(DummySubscriber):
- __implements__ = ISubscribingAware, ISubscriber
+class HasSubscribingAwareAdapter(DummySubscriber):
+ __implements__ = IHasSubscribingAwareAdapter, ISubscriber
+
+
+class SubscribingAwareAdapter(RecordingAdapter):
+
+ __implements__ = ISubscribingAware
def subscribedTo(self, subscribable, event_type, filter):
- self.subscribable = subscribable
- self.event_type = event_type
- self.filter = filter
+ self.record.append(('subscribed', self.context, subscribable,
+ event_type, filter))
def unsubscribedFrom(self, subscribable, event_type, filter):
- self.un_subscribable = subscribable
- self.un_event_type = event_type
- self.un_filter = filter
+ self.record.append(('unsubscribed', self.context, subscribable,
+ event_type, filter))
+
class TestEventPublisher(EventSetup, TestCase):
def setUp(self):
EventSetup.setUp(self)
- #sm = getServiceManager(None)
- #defineService = sm.defineService
- #provideService = sm.provideService
- #self.objectHub = DumbObjectHub()
-
- #defineService("HubIds", IObjectHub)
- #provideService("HubIds", self.objectHub)
def getObjectHub(self):
self.objectHub = DumbObjectHub()
@@ -866,10 +867,13 @@
configuration.status = Registered
def testSubscriptionAwareInteraction(self):
- sub = DummySubscriptionAwareSubscriber()
+ adapter = SubscribingAwareAdapter()
+ provideAdapter(IHasSubscribingAwareAdapter,
+ ISubscribingAware,
+ adapter)
self.rootFolder.setObject(
"mySubscriber",
- DummySubscriptionAwareSubscriber())
+ HasSubscribingAwareAdapter())
self.mySubscriber = ContextWrapper(
self.rootFolder["mySubscriber"],
self.rootFolder,
@@ -879,34 +883,45 @@
self.mySubscriber,
event_type=IObjectAddedEvent,
filter=filter)
- self.assertEqual(
- self.mySubscriber.subscribable,
- getEventService(self.rootFolder))
- self.assertEqual(
- self.mySubscriber.subscribable,
- getSubscriptionService(self.rootFolder))
- self.assertEqual(
- self.mySubscriber.event_type,
- IObjectAddedEvent)
- self.assertEqual(
- self.mySubscriber.filter,
- filter)
+ adapter.check(
+ ('subscribed',
+ self.mySubscriber,
+ getSubscriptionService(self.rootFolder),
+ IObjectAddedEvent,
+ filter
+ )
+ )
+ #self.assertEqual(
+ # self.mySubscriber.subscribable,
+ # getEventService(self.rootFolder))
+ #self.assertEqual(
+ # self.mySubscriber.subscribable,
+ # getSubscriptionService(self.rootFolder))
+ #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,
- getEventService(self.rootFolder))
- self.assertEqual(
- self.mySubscriber.un_subscribable,
- getSubscriptionService(self.rootFolder))
- self.assertEqual(
- self.mySubscriber.un_event_type,
- IObjectAddedEvent)
- self.assertEqual(
- self.mySubscriber.un_filter,
- filter)
+ adapter.check(
+ ('subscribed',
+ self.mySubscriber,
+ getSubscriptionService(self.rootFolder),
+ IObjectAddedEvent,
+ filter
+ ),
+ ('unsubscribed',
+ self.mySubscriber,
+ getSubscriptionService(self.rootFolder),
+ IObjectAddedEvent,
+ filter
+ )
+ )
+
def test_suite():