[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Service/tests - testServiceManager.py:1.1.2.1
Kapil
k_vertigo@yahoo.com
Fri, 8 Feb 2002 15:56:00 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Service/tests
In directory cvs.zope.org:/tmp/cvs-serv12657/Service/tests
Added Files:
Tag: Zope-3x-branch
testServiceManager.py
Log Message:
Added in interfaces and implementation for ServiceManagers in the
zodb instance space.
=== Added File Zope3/lib/python/Zope/App/Service/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/02/08 20:55:59 k_vertigo Exp $
"""
import unittest
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.Service.ServiceManager import ServiceManager
from Zope.ComponentArchitecture import getService, _clear
class ITestService(Interface): pass
class TestService:
__implements__ = ITestService
class ServiceManagerTests(unittest.TestCase):
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 testSetServiceManager(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
self.assertEqual(self.root.getServiceManager(), sm)
def testGetService(self):
sm = ServiceManager()
self.root.setServiceManager(sm)
ts = TestService()
sm.defineService('test_service', ITestService)
sm.provideService('test_service', ts)
import pdb; pdb.set_trace()
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.provideService('test_service', ts)
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.provideService('test_service', ts)
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=unittest.TestLoader()
return loader.loadTestsFromTestCase(ServiceManagerTests)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())