[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/CachingService/tests - testCachingService.py:1.4
Albertas Agejevas
alga@codeworks.lt
Fri, 6 Dec 2002 13:03:32 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/CachingService/tests
In directory cvs.zope.org:/tmp/cvs-serv32707/lib/python/Zope/App/OFS/Services/CachingService/tests
Modified Files:
testCachingService.py
Log Message:
Make CachingService an EventChannel.
On the way made LocalServiceSubscribable work when there is no next service.
=== Zope3/lib/python/Zope/App/OFS/Services/CachingService/tests/testCachingService.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/CachingService/tests/testCachingService.py:1.3 Fri Dec 6 06:01:11 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/CachingService/tests/testCachingService.py Fri Dec 6 13:03:31 2002
@@ -17,35 +17,79 @@
"""
from unittest import TestCase, TestSuite, main, makeSuite
-from Zope.App.tests.PlacelessSetup import PlacelessSetup
-from Zope.ComponentArchitecture.GlobalServiceManager import \
- serviceManager as sm
from Interface.Verify import verifyClass, verifyObject
-
from Zope.App.Caching.ICache import ICache
from Zope.App.Caching.ICachingService import ICachingService
+from Zope.App.OFS.Services.ConfigurationInterfaces import Active
+from Zope.App.OFS.Services.LocalEventService.tests.EventSetup import EventSetup
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
+ import ServiceConfiguration
+from Zope.App.Traversing import getPhysicalPathString, traverse
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
+from Zope.ComponentArchitecture import getServiceManager, getService
+from Zope.ComponentArchitecture.GlobalServiceManager \
+ import serviceManager as sm
+from Zope.Event.IObjectEvent import IObjectModifiedEvent
+
def sort(list):
list.sort()
return list
+
class CacheStub:
__implements__ = ICache
-class TestCachingService(PlacelessSetup, TestCase):
+
+class CachingServiceSetup(EventSetup):
def setUp(self):
+ EventSetup.setUp(self)
+
+ global_service_manager = getServiceManager(None)
+ global_service_manager.defineService("CachingService", ICachingService)
+ self.createCachingService()
+
+ def createCachingService(self, path=None):
from Zope.App.OFS.Services.CachingService.CachingService \
import CachingService
- PlacelessSetup.setUp(self)
+
+ folder = self.rootFolder
+ if path is not None:
+ folder = traverse(folder, path)
+
+ if not folder.hasServiceManager():
+ self.createServiceManager(folder)
+
+ sm = traverse(folder, '++etc++Services')
+ default = traverse(sm, 'Packages/default')
+ default.setObject("myCachingService", CachingService())
+
+ path = "%s/Packages/default/myCachingService" % getPhysicalPathString(sm)
+ configuration = ServiceConfiguration("CachingService", path)
+
+ configure = traverse(default, 'configure')
+ configure.setObject("myCachingServiceDir", configuration)
+
+ # XXX: This can't be the easiest way to activate the service!
+ for i in range(1, 100):
+ c = traverse(configure, str(i))
+ if c == configuration:
+ break
+
+ c.status = Active
+
+
+class TestCachingService(CachingServiceSetup, TestCase):
+
+ def setUp(self):
+ CachingServiceSetup.setUp(self)
self.cache1 = CacheStub()
self.cache2 = CacheStub()
- self.service = CachingService()
+ self.service = getService(self.rootFolder, "CachingService")
self.service.setObject('cache1', self.cache1)
self.service.setObject('cache2', self.cache2)
- sm.defineService('Caching', ICachingService)
- sm.provideService('Caching', self.service)
def test_interface(self):
from Zope.App.OFS.Services.CachingService.CachingService \
@@ -53,12 +97,12 @@
verifyObject(ILocalCachingService, self.service)
verifyObject(ICachingService, self.service)
- def testGetCache(self):
+ def test_getCache(self):
self.assertEqual(self.cache1,
self.service.getCache('cache1'))
self.assertRaises(KeyError, self.service.getCache, 'cache3')
- def testQueryCache(self):
+ def test_queryCache(self):
self.assertEqual(self.cache1,
self.service.queryCache('cache1'))
self.assertEqual(None,
@@ -66,13 +110,33 @@
self.assertEqual('Error',
self.service.queryCache('cache3', 'Error'))
- def testGetAvailableCaches(self):
+ def test_getAvailableCaches(self):
self.assertEqual(['cache1', 'cache2'],
sort(self.service.getAvailableCaches()))
- def testIsAddable(self):
+ def test_isAddable(self):
self.assertEqual(1, self.service.isAddable(ICache))
self.assertEqual(0, self.service.isAddable(ICachingService))
+
+ def test_setObject(self):
+ # setObject called in setUp... Ugh...
+ self.assertEqual(self.service.listSubscriptions(self.cache1),
+ [(IObjectModifiedEvent, None)])
+ self.assertEqual(self.service.listSubscriptions(self.cache2),
+ [(IObjectModifiedEvent, None)])
+
+ def test__delitem__(self):
+ self.assertEqual(self.service.listSubscriptions(self.cache1),
+ [(IObjectModifiedEvent, None)])
+ self.assertEqual(self.service.listSubscriptions(self.cache2),
+ [(IObjectModifiedEvent, None)])
+ del self.service['cache1']
+ self.assertEqual(self.service.listSubscriptions(self.cache1), [])
+ self.assertEqual(self.service.listSubscriptions(self.cache2),
+ [(IObjectModifiedEvent, None)])
+
+ del self.service['cache2']
+ self.assertEqual(self.service.listSubscriptions(self.cache2), [])
def test_suite():