[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager/tests - PlacefulSetup.py:1.1.2.1 testServiceManager.py:1.1.2.6
Gary Poster
garyposter@earthlink.net
Mon, 22 Apr 2002 15:03:52 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ServiceManager/tests
In directory cvs.zope.org:/tmp/cvs-serv31509/App/OFS/ServiceManager/tests
Modified Files:
Tag: Zope-3x-branch
testServiceManager.py
Added Files:
Tag: Zope-3x-branch
PlacefulSetup.py
Log Message:
1. As per ZopeTop discussion, moved Addable out of ZMI into the Services folder, and turned it into a true service (this involved a lot of small changes, particularly in the folders and a number of tests) and gave it some hooks
2. used SteveA's ContextWrapper.ContextMethod to make the ServiceManager and Services placefully look up to parent placeful equivalents
3. Made Event into a more standard service, and gave it some hooks
4. Built the beginning of a placeful EventService (will need tests, and views, and EventChannels, and more meat; just wanted to check this in for now)
5. made it so you can't add an item to a folder with a blank string id, and updated the folder interface
6. some typos fixed here and there
7. a few more tests here and there
I'm checking this in then checking it out again to check my work; also tagged previous version as gary-service_update.
=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/tests/PlacefulSetup.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Revision information:
$Id: PlacefulSetup.py,v 1.1.2.1 2002/04/22 19:03:21 poster Exp $
"""
class PlacefulSetup:
def getGlobalServiceManager_hook(self):
return self.serviceManager
def __init__(self):
# set up placeful hooks, saving originals for tearDown
from Zope.ComponentArchitecture import hooks
self.__old_getServiceManager_hook=hooks.getServiceManager_hook
self.__old_getNextServiceManager_hook=hooks.getNextServiceManager_hook
from Zope.App.OFS.ServiceManager import hooks as pHooks
hooks.getServiceManager_hook=pHooks.getServiceManager_hook
hooks.getNextServiceManager_hook=pHooks.getNextServiceManager_hook
# put in a temporary global service manager
self.__old_getGlobalServiceManager_hook=hooks.getGlobalServiceManager_hook
from Zope.ComponentArchitecture.Service import ServiceManager
self.serviceManager=ServiceManager()
hooks.getGlobalServiceManager_hook=self.getGlobalServiceManager_hook
# set up a reasonably complex folder structure
#
# ____________ rootFolder ____________
# / \
# folder1 __________________ folder2
# | \ |
# folder1_1 ____ folder1_2 folder2_1
# | \ | |
# folder1_1_1 folder1_1_2 folder1_2_1 folder2_1_1
from Zope.App.OFS.Folder.Folder import Folder
from Zope.App.OFS.Folder.RootFolder import RootFolder
from Zope.ContextWrapper import Wrapper
# top
self.rootFolder=RootFolder()
# level 1
self.folder1=Folder()
self.rootFolder.setObject("folder1",self.folder1)
self.folder1=Wrapper(self.folder1, self.rootFolder, name="folder1")
self.folder2=Folder()
self.rootFolder.setObject("folder2",self.folder2)
self.folder2=Wrapper(self.folder2, self.rootFolder, name="folder2")
# level 2
self.folder1_1=Folder()
self.folder1.setObject("folder1_1",self.folder1_1)
self.folder1_1=Wrapper(self.folder1_1, self.folder1, name="folder1_1")
self.folder1_2=Folder()
self.folder1.setObject("folder1_2",self.folder1_2)
self.folder1_2=Wrapper(self.folder1_2, self.folder1, name="folder1_2")
self.folder2_1=Folder()
self.folder2.setObject("folder2_1",self.folder2_1)
self.folder2_1=Wrapper(self.folder2_1, self.folder2, name="folder2_1")
# level 3
self.folder1_1_1=Folder()
self.folder1_1.setObject("folder1_1_1",self.folder1_1_1)
self.folder1_1_1=Wrapper(self.folder1_1_1, self.folder1_1, name="folder1_1_1")
self.folder1_1_2=Folder()
self.folder1_1.setObject("folder1_1_2",self.folder1_1_2)
self.folder1_1_2=Wrapper(self.folder1_1_2, self.folder1_1, name="folder1_1_2")
self.folder1_2_1=Folder()
self.folder1_2.setObject("folder1_2_1",self.folder1_2_1)
self.folder1_2_1=Wrapper(self.folder1_2_1, self.folder1_2, name="folder1_2_1")
self.folder2_1_1=Folder()
self.folder2_1.setObject("folder2_1_1",self.folder2_1_1)
self.folder2_1_1=Wrapper(self.folder2_1_1, self.folder2_1, name="folder2_1_1")
def tearDown(self):
from Zope.ComponentArchitecture import hooks
hooks.getServiceManager_hook=self.__old_getServiceManager_hook
hooks.getNextServiceManager_hook=self.__old_getNextServiceManager_hook
hooks.getGlobalServiceManager_hook=self.__old_getGlobalServiceManager_hook
=== Zope3/lib/python/Zope/App/OFS/ServiceManager/tests/testServiceManager.py 1.1.2.5 => 1.1.2.6 ===
from Zope.ComponentArchitecture import defineService
from Zope.Exceptions import ZopeError
-
-#set up hooks
-from Zope.App.OFS.ServiceManager.hooks import getServiceManager_hook, \
- getNextServiceManager_hook
-from Zope.ComponentArchitecture import hooks
-hooks.getServiceManager_hook=getServiceManager_hook
-hooks.getNextServiceManager_hook=getNextServiceManager_hook
+from Zope.ContextWrapper import Wrapper, getcontext
class ITestService(Interface): pass
@@ -48,85 +42,95 @@
return ServiceManager()
def setUp(self):
- root = RootFolder()
- self.root = root
- folder = Folder()
- root.setObject('folder', folder)
- self.folder = folder
- w = Wrapper(root, root.getObject('folder'))
- self.wrapped_folder = w
+ from PlacefulSetup import PlacefulSetup
+ self.__sandbox=PlacefulSetup()
+
+ def tearDown(self):
+ self.__sandbox.tearDown()
def testAddService(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
ts = TestService()
sm.setObject('test_service1', ts)
self.assertEqual(sm.getObject('test_service1'), ts)
def testGetService(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
- self.assertEqual(getService(self.root, 'test_service'), ts)
+ testOb=getService(self.__sandbox.rootFolder, 'test_service')
+ self.assertEqual(getcontext(getcontext(testOb)),self.__sandbox.rootFolder)
+ self.assertEqual(testOb, ts)
def testUnbindService(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
ts = TestService()
root_ts = TestService()
- defineService('test_service', ITestService)
- provideService('test_service', root_ts)
+ self.__sandbox.serviceManager.defineService('test_service', ITestService)
+ self.__sandbox.serviceManager.provideService('test_service', root_ts)
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
- self.assertEqual(getService(self.root, 'test_service'), ts)
+ self.assertEqual(getService(self.__sandbox.rootFolder, 'test_service'), ts)
sm.unbindService('test_service')
- self.assertEqual(getService(self.root, 'test_service'), root_ts)
+ self.assertEqual(getService(self.__sandbox.rootFolder, 'test_service'), root_ts)
def testDeleteService(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
- self.assertEqual(getService(self.root, 'test_service'), ts)
+ self.assertEqual(getService(self.__sandbox.rootFolder, 'test_service'), ts)
self.assertRaises(ZopeError, sm.delObject, 'test_service1')
def testContextServiceLookup(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
- self.assertEqual(getService(self.wrapped_folder, 'test_service'), ts)
+ self.assertEqual(getService(self.__sandbox.folder1, 'test_service'), ts)
+ self.assertEqual(getService(self.__sandbox.folder1_1, 'test_service'), ts)
def testContextServiceLookupWithMultipleServiceManagers(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
sm2 = ServiceManager()
- self.folder.setServiceManager(sm2)
+ self.__sandbox.folder1.setServiceManager(sm)
+ sm2=self.__sandbox.folder1.getServiceManager()
- self.assertEqual(getService(self.wrapped_folder, 'test_service'), ts)
+ self.assertEqual(getService(self.__sandbox.folder1, 'test_service'), ts)
def testComponentArchitectureServiceLookup(self):
sm = ServiceManager()
- self.root.setServiceManager(sm)
- sm = ServiceManager()
- self.folder.setServiceManager(sm)
+ self.__sandbox.rootFolder.setServiceManager(sm)
+ sm=self.__sandbox.rootFolder.getServiceManager()
+ sm2 = ServiceManager()
+ self.__sandbox.folder1.setServiceManager(sm)
+ sm2=self.__sandbox.folder1.getServiceManager()
ts = TestService()
- defineService('test_service', ITestService)
- provideService('test_service', ts)
+ self.__sandbox.serviceManager.defineService('test_service', ITestService)
+ self.__sandbox.serviceManager.provideService('test_service', ts)
- self.assertEqual(getService(self.wrapped_folder, 'test_service'), ts)
+ self.assertEqual(getService(self.__sandbox.folder1, 'test_service'), ts)