[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager/tests - __init__.py:1.1.2.1 testServiceManager.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 4 Mar 2002 11:48:20 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ServiceManager/tests
In directory cvs.zope.org:/tmp/cvs-serv12773/ServiceManager/tests
Added Files:
Tag: Zope-3x-branch
__init__.py testServiceManager.py
Log Message:
Moved ServiceManager code to OFS, which is just a logical place for
standard/default TTW object implementations.
Refactored SecurityManager to use container framework.
=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/tests/__init__.py ===
=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/tests/testServiceManager.py ===
##############################################################################
#
# Copyright (c) 2001 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/03/04 16:48:20 jim Exp $
"""
from unittest import TestCase, TestLoader, TextTestRunner
from Zope.App.OFS.Container.tests.testIContainer import BaseTestIContainer
from Interface import Interface
from Zope.App.OFS.Folder.RootFolder import RootFolder
from Zope.App.OFS.Folder.Folder import Folder
from Zope.ContextWrapper import Wrapper
from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.ComponentArchitecture import getService
class ITestService(Interface): pass
class TestService:
__implements__ = ITestService
class ServiceManagerTests(BaseTestIContainer, CleanUp, TestCase):
def _Test__new(self):
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
def testAddService(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
ts = TestService()
sm.setObject('test_service1', ts)
self.assertEqual(sm.getObject('test_service1'), ts)
def testGetService(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
ts = TestService()
sm.defineService('test_service', ITestService)
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
self.assertEqual(getService(self.root, 'test_service'), ts)
def testContextServiceLookup(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
ts = TestService()
sm.defineService('test_service', ITestService)
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
self.assertEqual(getService(self.wrapped_folder, 'test_service'), ts)
def testContextServiceLookupWithMultipleServiceManagers(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
ts = TestService()
sm.defineService('test_service', ITestService)
sm.setObject('test_service1', ts)
sm.bindService('test_service', 'test_service1')
sm2 = ServiceManager()
self.folder.setServiceManager(sm2)
self.assertEqual(getService(self.wrapped_folder, 'test_service'), ts)
def testComponentArchitectureServiceLookup(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
sm = ServiceManager()
self.folder.setServiceManager(sm)
ts = TestService()
from Zope.ComponentArchitecture.Service import serviceManager
serviceManager.defineService('test_service', ITestService)
serviceManager.provideService('test_service', ts)
self.assertEqual(getService(self.wrapped_folder, 'test_service'), ts)
def test_suite():
loader=TestLoader()
return loader.loadTestsFromTestCase(ServiceManagerTests)
if __name__=='__main__':
TextTestRunner().run(test_suite())