[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_cachingservice.py:1.4 test_eventservice.py:1.7
Steve Alexander
steve@cat-box.net
Mon, 3 Feb 2003 10:59:20 -0500
Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv23130/src/zope/app/services/tests
Modified Files:
test_cachingservice.py test_eventservice.py
Log Message:
Large event service reimplementation.
=== Zope3/src/zope/app/services/tests/test_cachingservice.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/tests/test_cachingservice.py:1.3 Mon Dec 30 09:03:17 2002
+++ Zope3/src/zope/app/services/tests/test_cachingservice.py Mon Feb 3 10:59:17 2003
@@ -42,6 +42,8 @@
def __repr__(self):
return "CacheStub(%r)" % self.name
+ def notify(self, event):
+ pass
class CachingServiceSetup(EventSetup):
@@ -54,7 +56,7 @@
if not folder.hasServiceManager():
self.createServiceManager(folder)
-
+
default = traverse(folder, '++etc++Services/Packages/default')
key = default.setObject("myCachingService", CachingService())
service = traverse(default, key)
@@ -68,8 +70,10 @@
return service
def addCache(self, name, cache=None, cname=None, status=Active, folder=''):
- if not cache: cache = CacheStub("%s/%s" % (folder, name))
- if not cname: cname = name
+ if not cache:
+ cache = CacheStub("%s/%s" % (folder, name))
+ if not cname:
+ cname = name
default = traverse(self.rootFolder,
folder +'/++etc++Services/Packages/default')
key = default.setObject(cname, cache)
@@ -94,8 +98,7 @@
self.cache4_f1 = self.addCache('cache4', folder='folder1')
def test_interface(self):
- from zope.app.services.cache \
- import ILocalCachingService
+ from zope.app.services.cache import ILocalCachingService
verifyObject(ILocalCachingService, self.service)
verifyObject(ICachingService, self.service)
=== Zope3/src/zope/app/services/tests/test_eventservice.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/services/tests/test_eventservice.py:1.6 Tue Jan 28 06:30:57 2003
+++ Zope3/src/zope/app/services/tests/test_eventservice.py Mon Feb 3 10:59:17 2003
@@ -24,8 +24,8 @@
from zope.app.services.event import EventService
from zope.app.traversing import getPhysicalPathString, traverse
from zope.exceptions import NotFoundError
-from zope.app.services.event import subscribe, unsubscribe
-from zope.app.services.event import listSubscriptions, getSubscriptionService
+from zope.app.services.event import subscribe, unsubscribe, unsubscribeAll
+from zope.app.services.event import iterSubscriptions, getSubscriptionService
from zope.app.event import getEventService, publish
from zope.app.event.tests.subscriber import DummySubscriber, DummyFilter
from zope.app.interfaces.event import IObjectEvent, IObjectModifiedEvent
@@ -63,23 +63,32 @@
def getHubId(object):
"gets hubid"
+ def getLocation(hubId):
+ "gets location"
+
class DumbObjectHub:
__implements__ = IObjectHub
def __init__(self):
+ # (location, object)
self.lib = []
def getObject(self, hubid):
try:
- return self.lib[hubid]
+ return self.lib[hubid][1]
except IndexError:
raise NotFoundError
- def getHubId(self, object):
+ def getHubId(self, object_or_path):
for i in range(len(self.lib)):
- if self.lib[i] is object:
+ if self.lib[i][0] == object_or_path:
+ return i
+ if self.lib[i][1] is object_or_path:
return i
- raise NotFoundError
+ raise NotFoundError, object_or_path
+
+ def getLocation(self, hubId):
+ return self.lib[hubId][0]
class IHasSubscribingAwareAdapter(Interface):
pass
@@ -134,9 +143,14 @@
def _createHubIdSubscribers(self):
self._createSubscribers()
- self.objectHub.lib = [self.rootFolderSubscriber,
- self.folder1Subscriber,
- self.folder1_1Subscriber]
+ self.objectHub.lib = [
+ ('/rootFolderSubscriber', self.rootFolderSubscriber),
+ ('/folder1/folder1Subscriber', self.folder1Subscriber),
+ ('/folder1/folder1_1/folder1_1Subscriber', self.folder1_1Subscriber)
+ ]
+ self.rootSubscriberHubId = 0
+ self.folder1SubscriberHubId = 1
+ self.folder1_1SubscriberHubId = 2
def testCreateNestedServices(self):
self._createNestedServices()
@@ -168,9 +182,9 @@
rootPath = getPhysicalPathString(self.rootFolderSubscriber)
folder1Path = getPhysicalPathString(self.folder1Subscriber)
folder1_1Path = getPhysicalPathString(self.folder1_1Subscriber)
- unsubscribe(rootPath, context=self.rootFolder)
+ unsubscribeAll(rootPath, context=self.rootFolder)
# curve ball:
- unsubscribe(self.folder1Subscriber, context=self.folder1_1)
+ unsubscribeAll(self.folder1Subscriber, context=self.folder1_1)
unsubscribe(folder1_1Path,
event_type=IObjectAddedEvent,
context=self.folder1_1)
@@ -191,27 +205,30 @@
folder1_1 = subscribe(self.folder1_1Subscriber,
event_type=IObjectAddedEvent)
self.assertEqual(
- self.objectHub.lib[root],
- self.rootFolderSubscriber)
+ self.objectHub.lib[self.rootSubscriberHubId],
+ ('/rootFolderSubscriber', self.rootFolderSubscriber)
+ )
self.assertEqual(
- self.objectHub.lib[folder1],
- self.folder1Subscriber)
+ self.objectHub.lib[self.folder1SubscriberHubId],
+ ('/folder1/folder1Subscriber', self.folder1Subscriber)
+ )
self.assertEqual(
- self.objectHub.lib[folder1_1],
- self.folder1_1Subscriber)
+ self.objectHub.lib[self.folder1_1SubscriberHubId],
+ ('/folder1/folder1_1/folder1_1Subscriber',
+ self.folder1_1Subscriber)
+ )
publish(self.folder1, ObjectAddedEvent(None, '/foo'))
self.assertEqual(self.rootFolderSubscriber.notified, 1)
self.assertEqual(self.folder1Subscriber.notified, 1)
self.assertEqual(self.folder1_1Subscriber.notified, 1)
- self.assertRaises(
- NotFoundError,
- unsubscribe,
- getPhysicalPathString(self.rootFolderSubscriber),
- event_type=IObjectAddedEvent,
- context=self.rootFolder)
- unsubscribe(root, context=self.rootFolder)
- # curve balls:
- unsubscribe(self.folder1Subscriber, context=self.folder1_1)
+ unsubscribe(getPhysicalPathString(self.rootFolderSubscriber),
+ event_type=IObjectAddedEvent,
+ context=self.rootFolder)
+ subscribe(self.rootFolderSubscriber,
+ event_type=IObjectAddedEvent)
+ unsubscribeAll(self.rootSubscriberHubId, context=self.rootFolder)
+ # curve balls:
+ unsubscribeAll(self.folder1Subscriber, context=self.folder1_1)
unsubscribe(2,
event_type=IObjectAddedEvent,
context=self.folder1_1)
@@ -249,15 +266,13 @@
self.assertEqual(self.rootFolderSubscriber.notified, 1)
self.assertEqual(self.folder1Subscriber.notified, 1)
self.assertEqual(self.folder1_1Subscriber.notified, 1)
- unsubscribe(rootPath, context=self.rootFolder)
- # curve balls:
- unsubscribe(self.folder1Subscriber, context=self.folder1_1)
- self.assertRaises(
- NotFoundError,
- unsubscribe,
- 2,
- event_type=IObjectAddedEvent,
- context=self.folder1_1)
+ unsubscribeAll(rootPath, context=self.rootFolder)
+ # curve balls:
+ unsubscribeAll(self.folder1Subscriber, context=self.folder1_1)
+ unsubscribe(2, event_type=IObjectAddedEvent, context=self.folder1_1)
+ subscribe(2, event_type=IObjectAddedEvent, context=self.folder1_1)
+
+ # this is supposed to unsubscribe '2'
unsubscribe(folder1_1Path,
event_type=IObjectAddedEvent,
context=self.folder1_1)
@@ -283,137 +298,156 @@
context = self.rootFolder)
self.assertEqual(
self.objectHub.lib[root],
- self.rootFolderSubscriber)
+ ('/rootFolderSubscriber', self.rootFolderSubscriber)
+ )
self.assertEqual(
self.objectHub.lib[folder1],
- self.folder1Subscriber)
+ ('/folder1/folder1Subscriber', self.folder1Subscriber)
+ )
self.assertEqual(
self.objectHub.lib[folder1_1],
- self.folder1_1Subscriber)
+ ('/folder1/folder1_1/folder1_1Subscriber',
+ self.folder1_1Subscriber)
+ )
publish(self.folder1, ObjectAddedEvent(None, '/foo'))
self.assertEqual(self.rootFolderSubscriber.notified, 1)
self.assertEqual(self.folder1Subscriber.notified, 1)
self.assertEqual(self.folder1_1Subscriber.notified, 1)
- self.assertRaises(
- NotFoundError,
- unsubscribe,
- getPhysicalPathString(self.rootFolderSubscriber),
- event_type = IObjectAddedEvent,
- context=self.rootFolder)
- unsubscribe(root, context=self.rootFolder)
- # curve ball:
- unsubscribe(self.folder1Subscriber, context=self.folder1_1)
+ unsubscribe(getPhysicalPathString(self.rootFolderSubscriber),
+ event_type=IObjectAddedEvent,
+ context=self.rootFolder)
+ subscribe(self.rootFolderSubscriber, event_type=IObjectAddedEvent,
+ context=self.rootFolder)
+ unsubscribeAll(root, context=self.rootFolder)
+ # curve ball:
+ unsubscribeAll(self.folder1Subscriber, context=self.folder1_1)
unsubscribe(2,
- event_type=IObjectAddedEvent,
+ event_type=IObjectAddedEvent,
context=self.folder1_1)
publish(self.folder1, ObjectAddedEvent(None, '/foo'))
self.assertEqual(self.rootFolderSubscriber.notified, 1)
self.assertEqual(self.folder1Subscriber.notified, 1)
self.assertEqual(self.folder1_1Subscriber.notified, 1)
- def _testListSubscriptions1(self):
+ def _testIterSubscriptions1(self):
# a non-subscribed subscriber gets an empty array
events = getSubscriptionService(self.rootFolder)
- self.assertEqual(events.listSubscriptions(self.rootFolderSubscriber),
- [])
+ self.assertEqual(
+ [x for x in events.iterSubscriptions(self.rootFolderSubscriber)],
+ [])
- def testPathListSubscriptions1(self):
+ def testPathIterSubscriptions1(self):
self._createSubscribers()
- self._testListSubscriptions1()
+ self._testIterSubscriptions1()
- def testHubIdListSubscriptions1(self):
+ def testHubIdIterSubscriptions1(self):
self._createHubIdSubscribers()
- self._testListSubscriptions1()
+ self._testIterSubscriptions1()
- def _testListSubscriptions2(self):
+ def _testIterSubscriptions2(self, subscription_type):
# one subscription
subscribe(
self.rootFolderSubscriber,
event_type=IObjectAddedEvent
)
- self.assertEqual([(IObjectAddedEvent,None)],
- getSubscriptionService(self.rootFolder)
- .listSubscriptions(self.rootFolderSubscriber))
+ if subscription_type is int:
+ reference = 0
+ else:
+ reference = u'/rootFolderSubscriber'
+ events = getSubscriptionService(self.rootFolder)
+ self.assertEqual(
+ [x for x in events.iterSubscriptions(self.rootFolderSubscriber)],
+ [(reference, IObjectAddedEvent, None)]
+ )
- def testPathListSubscriptions2(self):
+ def testPathIterSubscriptions2(self):
self._createSubscribers()
- self._testListSubscriptions2()
+ self._testIterSubscriptions2(unicode)
- def testHubIdListSubscriptions2(self):
+ def testHubIdIterSubscriptions2(self):
self._createHubIdSubscribers()
- self._testListSubscriptions2()
+ self._testIterSubscriptions2(int)
- def _testListSubscriptions3(self):
+ def _testIterSubscriptions3(self):
# listing limited subscription
subscribe(
self.rootFolderSubscriber,
event_type=IObjectAddedEvent
)
- self.assertEqual([],
- getSubscriptionService(self.rootFolder)
- .listSubscriptions(self.rootFolderSubscriber,
- IObjectRemovedEvent))
+ self.assertEqual(
+ [],
+ [x for x in getSubscriptionService(self.rootFolder)
+ .iterSubscriptions(self.rootFolderSubscriber, IObjectRemovedEvent)]
+ )
- def testPathListSubscriptions3(self):
+ def testPathIterSubscriptions3(self):
self._createSubscribers()
- self._testListSubscriptions3()
+ self._testIterSubscriptions3()
- def testHubIdListSubscriptions3(self):
+ def testHubIdIterSubscriptions3(self):
self._createHubIdSubscribers()
- self._testListSubscriptions3()
+ self._testIterSubscriptions3()
- def _testListSubscriptions4(self):
+ def _testIterSubscriptions4(self):
# a non-subscribed subscriber gets an empty array
events = getSubscriptionService(self.rootFolder)
- self.assertEqual(events.listSubscriptions(self.rootFolderSubscriber),
- [])
-
- def testPathListSubscriptions4(self):
- self._createSubscribers()
- self._testListSubscriptions4()
-
- def testHubIdListSubscriptions4(self):
+ self.assertEqual(
+ [x for x in events.iterSubscriptions(self.rootFolderSubscriber)],
+ [])
+
+ def testPathIterSubscriptions4(self):
+ self._createSubscribers()
+ self._testIterSubscriptions4()
+
+ def testHubIdIterSubscriptions4(self):
self._createHubIdSubscribers()
- self._testListSubscriptions4()
+ self._testIterSubscriptions4()
- def _testListSubscriptions5(self):
+ def _testIterSubscriptions5(self, subscription_type):
+ if subscription_type is int:
+ reference = 0
+ else:
+ reference = u'/rootFolderSubscriber'
# one subscription
subscribe(
self.rootFolderSubscriber,
event_type=IObjectAddedEvent
)
- self.assertEqual([(IObjectAddedEvent,None)],
- getSubscriptionService(self.rootFolder)
- .listSubscriptions(self.rootFolderSubscriber))
+ self.assertEqual(
+ [x for x in getSubscriptionService(self.rootFolder)
+ .iterSubscriptions(self.rootFolderSubscriber)],
+ [(reference, IObjectAddedEvent, None)]
+ )
- def testPathListSubscriptions5(self):
+ def testPathIterSubscriptions5(self):
self._createSubscribers()
- self._testListSubscriptions5()
+ self._testIterSubscriptions5(unicode)
- def testHubIdListSubscriptions5(self):
+ def testHubIdIterSubscriptions5(self):
self._createHubIdSubscribers()
- self._testListSubscriptions5()
+ self._testIterSubscriptions5(int)
- def _testListSubscriptions6(self):
+ def _testIterSubscriptions6(self):
# listing limited subscription
subscribe(
self.rootFolderSubscriber,
event_type=IObjectAddedEvent
)
- self.assertEqual([],
- getSubscriptionService(self.rootFolder)
- .listSubscriptions(self.rootFolderSubscriber,
- IObjectRemovedEvent))
+ self.assertEqual(
+ [x for x in getSubscriptionService(self.rootFolder)
+ .iterSubscriptions(self.rootFolderSubscriber, IObjectRemovedEvent)],
+ []
+ )
- def testPathListSubscriptions6(self):
+ def testPathIterSubscriptions6(self):
self._createSubscribers()
- self._testListSubscriptions6()
+ self._testIterSubscriptions6()
- def testHubIdListSubscriptions6(self):
+ def testHubIdIterSubscriptions6(self):
self._createHubIdSubscribers()
- self._testListSubscriptions6()
+ self._testIterSubscriptions6()
def _testSubscribe1(self):
# Test subscribe method with one parameter
@@ -576,7 +610,7 @@
)
publish(self.folder1_1_1, ObjectAddedEvent(None, '/foo'))
self.assertEqual(self.rootFolderSubscriber.notified, 1)
- unsubscribe(
+ unsubscribeAll(
self.rootFolderSubscriber
)
publish(self.folder1_1_1, ObjectAddedEvent(None, '/foo'))
@@ -594,10 +628,9 @@
# Test unsubscribe of something that hasn't been subscribed
self.assertRaises(NotFoundError,
unsubscribe,
- self.rootFolderSubscriber,
+ 69,
IObjectEvent)
- self.assertEqual(None,
- unsubscribe(self.rootFolderSubscriber))
+ unsubscribeAll(self.rootFolderSubscriber)
def testPathUnsubscribe2(self):
self._createSubscribers()
@@ -609,11 +642,11 @@
def _testUnsubscribe3(self):
# Test selective unsubscribe
- subscriber=self.rootFolderSubscriber
- subscriber2=self.folder1Subscriber
- filter=DummyFilter()
- event=ObjectAddedEvent(None, '/foo')
- event2=ObjectModifiedEvent(None, '/foo')
+ subscriber = self.rootFolderSubscriber
+ subscriber2 = self.folder1Subscriber
+ filter = DummyFilter()
+ event = ObjectAddedEvent(None, '/foo')
+ event2 = ObjectModifiedEvent(None, '/foo')
subscribe(
subscriber)
subscribe(
@@ -836,7 +869,6 @@
sm = traverse(self.rootFolder, "folder1/++etc++Services")
configuration = sm.queryConfigurations("Events").active()
configuration.status = Registered
-
publish(self.rootFolder, ObjectAddedEvent(None, '/foo'))
self.assertEqual(self.folder1Subscriber.notified, 1)
self.assertEqual(self.folder1_1Subscriber.notified, 1)