[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests - PlacefulSetup.py:1.1.2.1 __init__.py:1.1.2.1 testServiceManager.py:1.1.2.1 tmp:NONE
Christian Theune
ct@gocept.com
Sat, 25 May 2002 06:03:31 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests
In directory cvs.zope.org:/tmp/cvs-serv9745
Added Files:
Tag: ctheune-services_move-branch
PlacefulSetup.py __init__.py testServiceManager.py
Removed Files:
Tag: ctheune-services_move-branch
tmp
Log Message:
Added some files of the ServiceManager, i forgot in the first step.
=== Added File Zope3/lib/python/Zope/App/OFS/Services/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/05/25 10:03:30 ctheune Exp $
"""
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
class PlacefulSetup(PlacelessSetup):
def setUp(self):
PlacelessSetup.setUp(self)
# set up placeful hooks, saving originals for tearDown
from Zope import ComponentArchitecture as CA
self.__old_getServiceManager_hook=CA.getServiceManager_hook
self.__old_getNextServiceManager_hook=CA.getNextServiceManager_hook
from Zope.App.OFS.ServiceManager import hooks
CA.getServiceManager_hook=hooks.getServiceManager_hook
CA.getNextServiceManager_hook=hooks.getNextServiceManager_hook
def buildFolders(self):
# 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.Content.Folder.Folder import Folder
from Zope.App.OFS.Content.Folder.RootFolder import RootFolder
from Zope.Proxy.ContextWrapper import ContextWrapper
# top
self.rootFolder=RootFolder()
# level 1
self.folder1=Folder()
self.rootFolder.setObject("folder1",self.folder1)
self.folder1=ContextWrapper(self.folder1, self.rootFolder,
name="folder1")
self.folder2=Folder()
self.rootFolder.setObject("folder2",self.folder2)
self.folder2=ContextWrapper(self.folder2, self.rootFolder,
name="folder2")
# level 2
self.folder1_1=Folder()
self.folder1.setObject("folder1_1",self.folder1_1)
self.folder1_1=ContextWrapper(self.folder1_1, self.folder1,
name="folder1_1")
self.folder1_2=Folder()
self.folder1.setObject("folder1_2",self.folder1_2)
self.folder1_2=ContextWrapper(self.folder1_2, self.folder1,
name="folder1_2")
self.folder2_1=Folder()
self.folder2.setObject("folder2_1",self.folder2_1)
self.folder2_1=ContextWrapper(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=ContextWrapper(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=ContextWrapper(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=ContextWrapper(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=ContextWrapper(self.folder2_1_1, self.folder2_1,
name="folder2_1_1")
def createServiceManager(self, folder=None):
if folder is None: folder=self.rootFolder
from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
folder.setServiceManager(ServiceManager())
def tearDown(self):
# clean up folders and placeful service managers and services too?
from Zope import ComponentArchitecture as CA
CA.getServiceManager_hook=self.__old_getServiceManager_hook
CA.getNextServiceManager_hook=self.__old_getNextServiceManager_hook
PlacelessSetup.tearDown(self)
=== Added File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/__init__.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.
#
##############################################################################
=== Added File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.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: testServiceManager.py,v 1.1.2.1 2002/05/25 10:03:30 ctheune Exp $
"""
from unittest import TestCase, TestLoader, TextTestRunner
from Zope.App.OFS.Container.tests.testIContainer import BaseTestIContainer
from Interface import Interface
from Zope.App.OFS.Content.Folder.RootFolder import RootFolder
from Zope.App.OFS.Content.Folder.Folder import Folder
from Zope.Proxy.ContextWrapper import getWrapperContext
from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
from Zope.ComponentArchitecture import getService, getServiceManager
from Zope.Exceptions import ZopeError
from PlacefulSetup import PlacefulSetup
class ITestService(Interface): pass
class TestService:
__implements__ = ITestService
class ServiceManagerTests(PlacefulSetup, BaseTestIContainer, TestCase):
def setUp(self):
PlacefulSetup.setUp(self)
self.buildFolders()
def _Test__new(self):
return ServiceManager()
def testAddService(self):
sm = ServiceManager()
self.rootFolder.setServiceManager(sm)
sm=getServiceManager(self.rootFolder)
ts = TestService()
sm.setObject('test_service1', ts)
self.assertEqual(sm.getObject('test_service1'), ts)
def testGetService(self):
sm = ServiceManager()
self.rootFolder.setServiceManager(sm)
sm=getServiceManager(self.rootFolder)
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
testOb=getService(self.rootFolder, 'test_service')
self.assertEqual(getWrapperContext
(getWrapperContext(testOb)),self.rootFolder)
self.assertEqual(testOb, ts)
def testUnbindService(self):
sm = ServiceManager()
self.rootFolder.setServiceManager(sm)
sm=getServiceManager(self.rootFolder)
ts = TestService()
root_ts = TestService()
gsm=getServiceManager(None)
gsm.defineService('test_service', ITestService)
gsm.provideService('test_service', root_ts)
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
self.assertEqual(getService(self.rootFolder, 'test_service'), ts)
sm.unbindService('test_service')
self.assertEqual(getService(self.rootFolder, 'test_service'), root_ts)
def testDeleteService(self):
self.rootFolder.setServiceManager(ServiceManager())
sm=getServiceManager(self.rootFolder)
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
self.assertEqual(getService(self.rootFolder, 'test_service'), ts)
self.assertRaises(ZopeError, sm.delObject, 'test_service1')
def testContextServiceLookup(self):
self.rootFolder.setServiceManager(ServiceManager())
sm=getServiceManager(self.rootFolder)
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
self.assertEqual(getService(self.folder1, 'test_service'), ts)
self.assertEqual(getService(self.folder1_1, 'test_service'), ts)
def testContextServiceLookupWithMultipleServiceManagers(self):
self.rootFolder.setServiceManager(ServiceManager())
sm=getServiceManager(self.rootFolder)
ts = TestService()
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
self.folder1.setServiceManager(ServiceManager())
sm2=getServiceManager(self.folder1)
self.assertEqual(getService(self.folder1, 'test_service'), ts)
def testComponentArchitectureServiceLookup(self):
self.rootFolder.setServiceManager(ServiceManager())
sm=getServiceManager(self.rootFolder)
self.folder1.setServiceManager(ServiceManager())
sm2=getServiceManager(self.folder1)
ts = TestService()
globsm=getServiceManager(None)
globsm.defineService('test_service', ITestService)
globsm.provideService('test_service', ts)
self.assertEqual(getService(self.folder1, 'test_service'), ts)
def test_suite():
loader=TestLoader()
return loader.loadTestsFromTestCase(ServiceManagerTests)
if __name__=='__main__':
TextTestRunner().run(test_suite())
=== Removed File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/tmp ===