[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests - Sample1.py:1.2 Sample2.py:1.2 testConfigurationManager.py:1.2 testServiceConfiguration.py:1.2 PlacefulSetup.py:1.7 testServiceManager.py:1.4 TestingServiceManager.py:NONE testServiceDirective.py:NONE
Jim Fulton
jim@zope.com
Sat, 30 Nov 2002 13:39:19 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests
In directory cvs.zope.org:/tmp/cvs-serv12171/lib/python/Zope/App/OFS/Services/ServiceManager/tests
Modified Files:
PlacefulSetup.py testServiceManager.py
Added Files:
Sample1.py Sample2.py testConfigurationManager.py
testServiceConfiguration.py
Removed Files:
TestingServiceManager.py testServiceDirective.py
Log Message:
- Updated to use new configuration framework.
- Updated PlacefulSetup to register the standard traversal adapters
and views during setup.
- Service managers now support hierarchical module lookup.
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/Sample1.py 1.1 => 1.2 ===
--- /dev/null Sat Nov 30 13:39:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/Sample1.py Sat Nov 30 13:39:18 2002
@@ -0,0 +1 @@
+x = 'sample 1'
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/Sample2.py 1.1 => 1.2 ===
--- /dev/null Sat Nov 30 13:39:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/Sample2.py Sat Nov 30 13:39:18 2002
@@ -0,0 +1 @@
+y = 'sample 2'
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testConfigurationManager.py 1.1 => 1.2 ===
--- /dev/null Sat Nov 30 13:39:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testConfigurationManager.py Sat Nov 30 13:39:18 2002
@@ -0,0 +1,325 @@
+##############################################################################
+#
+# Copyright (c) 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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from Zope.App.OFS.Services.ServiceManager.ConfigurationManager \
+ import ConfigurationManager
+from Zope.App.OFS.Services.ServiceManager.IConfigurationManager \
+ import IConfigurationManager
+from unittest import TestCase, TestSuite, main, makeSuite
+from Interface.Common.tests.BaseTestMapping import BaseTestIEnumerableMapping
+from Interface.Verify import verifyObject
+
+class Test(BaseTestIEnumerableMapping, TestCase):
+
+ """Testing for Configuration Manager """
+
+ def setUp(self):
+ self.__manager = manager = ConfigurationManager()
+ for l in 'abcdefghijklmnop':
+ manager.setObject('', l)
+ del manager['8']
+ del manager['10']
+
+ def test_implements_IConfigurationManager(self):
+ verifyObject(IConfigurationManager, self.__manager)
+
+ def _IEnumerableMapping__stateDict(self):
+ # Hook needed by BaseTestIEnumerableMapping
+ # also, effectively test setObject and __delitem__.
+ return {
+ '1': 'a', '2': 'b', '3': 'c', '4': 'd', '5': 'e',
+ '6': 'f', '7': 'g', '9': 'i', '11': 'k', '12': 'l',
+ '13': 'm', '14': 'n', '15': 'o', '16': 'p',
+ }
+
+ def _IEnumerableMapping__sample(self):
+ # Hook needed by BaseTestIEnumerableMapping
+ # also, effectively test setObject and __delitem__.
+ return self.__manager
+
+ def _IEnumerableMapping__absentKeys(self):
+ # Hook needed by BaseTestIEnumerableMapping
+ # also, effectively test setObject and __delitem__.
+ return ['-1', '8', '10', '17', '100', '10000']
+
+ #########################################################
+ # Move Top
+
+ def test_moveTop_nothing(self):
+ self.__manager.moveTop([])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveTop_1_no_effect(self):
+ self.__manager.moveTop(['1'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveTop_many_no_effect(self):
+ self.__manager.moveTop(['1', '88', '3', '2', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveTop_1(self):
+ self.__manager.moveTop(['3'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['3', '1', '2', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveTop_many(self):
+ self.__manager.moveTop(['1', '3', '88', '4', '11', '15', '16', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '3', '4', '11', '15', '16', '2', '5', '6', '7', '9',
+ '12', '13', '14'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveTop_one_element_container(self):
+ manager = ConfigurationManager()
+ manager.setObject('', 'a')
+ manager.moveTop(['1'])
+ self.assertEqual(list(manager.items()), [('1', 'a')])
+
+ #########################################################
+ # Move Bottom
+
+ def test_moveBottom_nothing(self):
+ self.__manager.moveBottom([])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveBottom_1_no_effect(self):
+ self.__manager.moveBottom(['16'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveBottom_many_no_effect(self):
+ self.__manager.moveBottom(['14', '88', '16', '15', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveBottom_1(self):
+ self.__manager.moveBottom(['3'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16', '3'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveBottom_many(self):
+ self.__manager.moveBottom(
+ ['1', '3', '88', '4', '11', '16', '15', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['2', '5', '6', '7', '9',
+ '12', '13', '14', '1', '3', '4', '11', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveBottom_one_element_container(self):
+ manager = ConfigurationManager()
+ manager.setObject('', 'a')
+ manager.moveBottom(['1'])
+ self.assertEqual(list(manager.items()), [('1', 'a')])
+
+ #########################################################
+ # Move Up
+
+ def test_moveUp_nothing(self):
+ self.__manager.moveUp([])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveUp_1_no_effect(self):
+ self.__manager.moveUp(['1'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveUp_many_no_effect(self):
+ self.__manager.moveUp(['1', '88', '3', '2', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveUp_1(self):
+ self.__manager.moveUp(['3'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '3', '2', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveUp_many(self):
+ self.__manager.moveUp(
+ ['1', '3', '88', '4', '11', '16', '15', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '3', '4', '2', '5', '6', '7', '11', '9',
+ '12', '13', '15', '16', '14'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveUp_one_element_container(self):
+ manager = ConfigurationManager()
+ manager.setObject('', 'a')
+ manager.moveUp(['1'])
+ self.assertEqual(list(manager.items()), [('1', 'a')])
+
+ #########################################################
+ # Move Down
+
+ def test_moveDown_nothing(self):
+ self.__manager.moveDown([])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveDown_1_no_effect(self):
+ self.__manager.moveDown(['16'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveDown_many_no_effect(self):
+ self.__manager.moveDown(['16', '88', '14', '15', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '3', '4', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveDown_1(self):
+ self.__manager.moveDown(['3'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['1', '2', '4', '3', '5', '6', '7', '9',
+ '11', '12', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveDown_many(self):
+ self.__manager.moveDown(
+ ['1', '3', '88', '4', '11', '16', '15', '99'])
+ self.assertEqual(
+ list(self.__manager.keys()),
+ ['2', '1', '5', '3', '4', '6', '7', '9',
+ '12', '11', '13', '14', '15', '16'],
+ )
+
+ # Make sure we still have thye right items
+ self.test_items()
+
+ def test_moveDown_one_element_container(self):
+ manager = ConfigurationManager()
+ manager.setObject('', 'a')
+ manager.moveDown(['1'])
+ self.assertEqual(list(manager.items()), [('1', 'a')])
+
+
+
+
+def test_suite():
+ return makeSuite(Test)
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceConfiguration.py 1.1 => 1.2 ===
--- /dev/null Sat Nov 30 13:39:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceConfiguration.py Sat Nov 30 13:39:18 2002
@@ -0,0 +1,144 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from Interface import Interface
+
+from Zope.ComponentArchitecture import getServiceManager
+from Zope.App.Traversing import traverse
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
+ import ServiceConfiguration
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
+ import PlacefulSetup
+from Zope.App.OFS.Services.ServiceManager.ServiceManager \
+ import ServiceManager
+from Zope.ComponentArchitecture.GlobalServiceManager \
+ import serviceManager
+from Zope.App.OFS.Services.ServiceManager.IBindingAware \
+ import IBindingAware
+from Zope.App.OFS.Services.ConfigurationInterfaces \
+ import Active, Unregistered, Registered
+
+from Zope.App.DependencyFramework.IDependable import IDependable
+from Zope.App.DependencyFramework.Exceptions import DependencyError
+
+from Zope.App.OFS.Container.ZopeContainerAdapter import ZopeContainerAdapter
+
+
+class ITestService(Interface):
+ pass
+
+class TestService:
+ __implements__ = ITestService, IBindingAware, IDependable
+
+ _bound = _unbound = ()
+
+ def bound(self, name):
+ self._bound += (name, )
+
+ def unbound(self, name):
+ self._unbound += (name, )
+
+ _dependents = ()
+
+ def addDependent(self, location):
+ self._dependents = tuple(
+ [d for d in self._dependents if d != location]
+ +
+ [location]
+ )
+
+ def removeDependent(self, location):
+ self._dependents = tuple(
+ [d for d in self._dependents if d != location]
+ )
+
+ def dependents(self):
+ return self._dependents
+
+class Test(PlacefulSetup, TestCase):
+
+ def setUp(self):
+ PlacefulSetup.setUp(self)
+ self.buildFolders()
+ self.rootFolder.setServiceManager(ServiceManager())
+ serviceManager.defineService('test_service', ITestService)
+ default = traverse(self.rootFolder,
+ '++etc++Services/Packages/default')
+ self.__default = default
+
+ default.setObject('c', TestService())
+
+
+ configuration = ServiceConfiguration(
+ 'test_service', '/++etc++Services/Packages/default/c')
+
+ self.__c = traverse(default, 'c')
+ self.__cm = ZopeContainerAdapter(traverse(default, "configure"))
+
+ self.__cm.setObject('', configuration)
+
+ self.__config = traverse(default, 'configure/1')
+
+ def test_getService(self):
+ self.assertEqual(self.__config.getService(), self.__c)
+
+ def test_activated(self):
+ old = self.__c._bound
+ self.__config.activated()
+ self.assertEqual(self.__c._bound, old+('test_service',))
+
+ def test_deactivated(self):
+ old = self.__c._unbound
+ self.__config.deactivated()
+ self.assertEqual(self.__c._unbound, old+('test_service',))
+
+ def test_manage_afterAdd(self):
+ self.assertEqual(self.__c._dependents,
+ ('/++etc++Services/Packages/default/configure/1', ))
+
+ def test_manage_beforeDelete_and_unregistered(self):
+ self.__config.status = Registered
+
+ sm = getServiceManager(self.__default)
+ registry = sm.queryConfigurationsFor(self.__config)
+ self.failUnless(registry, "The components should be registered")
+
+ del self.__cm['1']
+ self.assertEqual(self.__c._dependents, ())
+
+ self.failIf(registry, "The components should not be registered")
+
+ def test_disallow_delete_when_active(self):
+ self.__config.status = Active
+ try:
+ del self.__cm['1']
+ except DependencyError:
+ pass # OK
+ else:
+ self.failUnless(0, "Should have gotten a depency error")
+
+
+def test_suite():
+ return makeSuite(Test)
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/PlacefulSetup.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/PlacefulSetup.py:1.6 Fri Oct 4 14:37:22 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/PlacefulSetup.py Sat Nov 30 13:39:18 2002
@@ -17,24 +17,65 @@
$Id$
"""
from Zope.App.tests.PlacelessSetup import PlacelessSetup
+from Zope import ComponentArchitecture as CA
+from Zope.App.ComponentArchitecture import hooks
+from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
+
+from Zope.App.Traversing import getPhysicalPathString
+from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
+from Zope.App.Traversing.EtcNamespace import etc
+from Zope.App.Traversing.IContainmentRoot import IContainmentRoot
+from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
+from Zope.App.Traversing.ITraverser import ITraverser
+from Zope.App.Traversing.ITraversable import ITraversable
+from Zope.App.Traversing.Namespaces import provideNamespaceHandler
+from Zope.App.Traversing.PhysicalLocationAdapters \
+ import WrapperPhysicallyLocatable, RootPhysicallyLocatable
+from Zope.App.Traversing.Traverser import Traverser
+
+from Zope.App.OFS.Content.Folder.RootFolder import IRootFolder
+
+
+from Zope.App.OFS.Container.IContainer import ISimpleReadContainer
+from Zope.App.OFS.Container.ContainerTraversable import ContainerTraversable
+
+from Zope.ComponentArchitecture.GlobalViewService import provideView
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.App.ZopePublication.TraversalViews.AbsoluteURL \
+ import SiteAbsoluteURL, AbsoluteURL
class PlacefulSetup(PlacelessSetup):
def setUp(self):
PlacelessSetup.setUp(self)
- # set up etc namespace
- from Zope.App.Traversing.Namespaces import provideNamespaceHandler
- from Zope.App.Traversing.EtcNamespace import etc
- provideNamespaceHandler("etc", etc)
# set up placeful hooks, saving originals for tearDown
- from Zope import ComponentArchitecture as CA
self.__old_getServiceManager_hook = CA.getServiceManager_hook
- from Zope.App.ComponentArchitecture import hooks
CA.getServiceManager_hook = hooks.getServiceManager_hook
+ self.setUpTraversal()
+
+ def setUpTraversal(self):
+
+ provideAdapter(None, ITraverser, Traverser)
+ provideAdapter(None, ITraversable, DefaultTraversable)
+
+ provideAdapter(
+ ISimpleReadContainer, ITraversable, ContainerTraversable)
+ provideAdapter(
+ None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+ provideAdapter(
+ IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
+
+ # set up etc namespace
+ provideNamespaceHandler("etc", etc)
+
+ provideView(None, "absolute_url", IBrowserPresentation,
+ AbsoluteURL)
+ provideView(IRootFolder, "absolute_url", IBrowserPresentation,
+ SiteAbsoluteURL)
+
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
PlacelessSetup.tearDown(self)
@@ -94,8 +135,10 @@
name = "folder2_1_1")
def createServiceManager(self, folder = None):
- if folder is None: folder = self.rootFolder
- from Zope.App.OFS.Services.ServiceManager.ServiceManager \
- import ServiceManager
- folder.setServiceManager(ServiceManager())
+ if folder is None:
+ folder = self.rootFolder
+ from Zope.App.OFS.Services.tests.TestingServiceManager \
+ import TestingServiceManager
+
+ folder.setServiceManager(TestingServiceManager())
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.py:1.3 Thu Jul 11 14:21:33 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.py Sat Nov 30 13:39:18 2002
@@ -23,18 +23,19 @@
from Zope.App.OFS.Content.Folder.Folder import Folder
from Zope.Proxy.ContextWrapper import getWrapperContext, getWrapperContainer
from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
-from Zope.App.OFS.Services.ServiceManager.ServiceDirective \
- import ServiceDirective
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
+ import ServiceConfiguration
from Zope.ComponentArchitecture import getService, getServiceManager
from Zope.Exceptions import ZopeError
from PlacefulSetup import PlacefulSetup
+from Zope.App.Traversing import traverse
+from Zope.App.OFS.Services.ConfigurationInterfaces \
+ import Active, Unregistered, Registered
+from Zope.ComponentArchitecture.GlobalServiceManager \
+ import serviceManager
-from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
-from Zope.App.Traversing.IContainmentRoot import IContainmentRoot
-from Zope.App.Traversing.PhysicalLocationAdapters \
- import WrapperPhysicallyLocatable, RootPhysicallyLocatable
-
-class ITestService(Interface): pass
+class ITestService(Interface):
+ pass
class TestService:
@@ -45,41 +46,28 @@
def setUp(self):
PlacefulSetup.setUp(self)
self.buildFolders()
- from Zope.ComponentArchitecture.GlobalAdapterService \
- import provideAdapter
- from Zope.App.OFS.Services.ServiceManager.IServiceManager \
- import IServiceManager
- from Zope.App.Traversing.ITraversable import ITraversable
- from Zope.App.OFS.Container.IContainer import ISimpleReadContainer
- from Zope.App.OFS.Container.ContainerTraversable \
- import ContainerTraversable
-
- provideAdapter(ISimpleReadContainer, ITraversable,
- ContainerTraversable)
- provideAdapter(
- None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
- provideAdapter(
- IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
-
- from Zope.ComponentArchitecture.GlobalServiceManager \
- import serviceManager
serviceManager.defineService('test_service', ITestService)
def _Test__new(self):
return ServiceManager()
+ def createServiceManager(self):
+ self.rootFolder.setServiceManager(ServiceManager())
+
def testGetService(self):
- sm = ServiceManager()
- self.rootFolder.setServiceManager(sm)
- sm = getServiceManager(self.rootFolder)
+ self.createServiceManager()
+ sm = traverse(self.rootFolder, '++etc++Services')
+ default = traverse(sm, 'Packages/default')
+
ts = TestService()
- sm.Packages['default'].setObject('test_service1', ts)
- directive = ServiceDirective(
+ default.setObject('test_service1', ts)
+ configuration = ServiceConfiguration(
'test_service',
'/++etc++Services/Packages/default/test_service1')
- sm.Packages['default'].setObject('test_service1_dir', directive)
- sm.bindService(directive)
+
+ default['configure'].setObject('', configuration)
+ traverse(default, 'configure/1').status = Active
testOb = getService(self.rootFolder, 'test_service')
c = getWrapperContainer
@@ -87,27 +75,28 @@
self.assertEqual(testOb, ts)
def testAddService(self):
- sm = ServiceManager()
- self.rootFolder.setServiceManager(sm)
- sm = getServiceManager(self.rootFolder)
- ts = TestService()
- sm.Packages['default'].setObject('test_service1', ts)
- directive = ServiceDirective(
+ self.createServiceManager()
+ sm = traverse(self.rootFolder, '++etc++Services')
+ default = traverse(sm, 'Packages/default')
+
+ ts1 = TestService()
+ default.setObject('test_service1', ts1)
+ configuration = ServiceConfiguration(
'test_service',
'/++etc++Services/Packages/default/test_service1')
- sm.Packages['default'].setObject('test_service1_dir', directive)
- sm.bindService(directive)
+ default['configure'].setObject('', configuration)
+ traverse(default, 'configure/1').status = Active
ts2 = TestService()
- sm.Packages['default'].setObject('test_service2', ts)
- directive = ServiceDirective(
+ default.setObject('test_service2', ts2)
+ configuration = ServiceConfiguration(
'test_service',
'/++etc++Services/Packages/default/test_service2')
- sm.Packages['default'].setObject('test_service2_dir', directive)
- sm.bindService(directive)
+ default['configure'].setObject('', configuration)
+ traverse(default, 'configure/2').status = Registered
testOb = getService(self.rootFolder, 'test_service')
- self.assertEqual(testOb, ts)
+ self.assertEqual(testOb, ts1)
def testUnbindService(self):
@@ -118,24 +107,10 @@
self.testGetService() # set up localservice
- sm = getServiceManager(self.rootFolder)
-
- directive = sm.Packages['default']['test_service1_dir']
- sm.unbindService(directive)
- self.assertEqual(getService(self.rootFolder, 'test_service'), root_ts)
-
- # XXX This should be a test on the adapter responsible for deleting.
- def __testDeleteService(self):
- """sure deleting a service generates a service generates a
- removed event."""
- self.rootFolder.setServiceManager(ServiceManager())
- sm=getServiceManager(self.rootFolder)
- ts = TestService()
+ sm = traverse(self.rootFolder, '++etc++Services')
+ traverse(sm, 'Packages/default/configure/1').status = Unregistered
- sm.setObject('test_service1', ts)
- sm.bindService('test_service', 'test_service1')
- self.assertEqual(getService(self.rootFolder, 'test_service'), ts)
- self.assertRaises(ZopeError, sm.__delitem__, 'test_service1')
+ self.assertEqual(getService(self.rootFolder, 'test_service'), root_ts)
def testContextServiceLookup(self):
self.testGetService() # set up localservice
@@ -165,7 +140,55 @@
service = getService(self.folder1, 'test_service')
self.assertEqual(service, ts)
+ def test_resolve(self):
+ from Zope.Proxy.ContextWrapper import ContextWrapper as cw
+ from Zope.App.OFS.Services.ServiceManager.Module import Manager
+ import Zope.App.OFS.Services.ServiceManager.tests.Sample1
+ import Zope.App.OFS.Services.ServiceManager.tests.Sample2
+
+ self.rootFolder.setServiceManager(ServiceManager())
+ sm=getServiceManager(self.rootFolder)
+ Packages = cw(sm.Packages, sm, name='Packages')
+ default = cw(Packages['default'], Packages, name='Packages')
+ default.setObject('m1', Manager())
+ manager = cw(default['m1'], default, name='m1')
+ manager.new('Zope.App.OFS.Services.ServiceManager.tests.Sample1',
+ 'x = "root m1"\n')
+ default.setObject('m2', Manager())
+ manager = cw(default['m2'], default, name='m1')
+ manager.new('XXX.ZZZ', 'x = "root m2"\nZZZ = 42\n')
+ self.folder1.setServiceManager(ServiceManager())
+ sm2=getServiceManager(self.folder1)
+ Packages = cw(sm2.Packages, sm2, name='Packages')
+ default = cw(Packages['default'], Packages, name='Packages')
+ default.setObject('m1', Manager())
+ manager = cw(default['m1'], default, name='m1')
+ manager.new('Zope.App.OFS.Services.ServiceManager.tests.Sample1',
+ 'x = "folder1 m1 1"')
+
+ self.assertEqual(
+ sm2.resolve("Zope.App.OFS.Services.ServiceManager.tests.Sample1.x"),
+ "folder1 m1 1")
+ self.assertEqual(
+ sm.resolve("Zope.App.OFS.Services.ServiceManager.tests.Sample1.x"),
+ "root m1")
+
+ self.assertEqual(
+ sm2.resolve("Zope.App.OFS.Services.ServiceManager.tests.Sample2.y"),
+ "sample 2")
+ self.assertEqual(
+ sm.resolve("Zope.App.OFS.Services.ServiceManager.tests.Sample2.y"),
+ "sample 2")
+
+ self.assertEqual(sm.resolve("XXX.ZZZ.ZZZ"), 42)
+ self.assertEqual(sm.resolve("XXX.ZZZ."), 42)
+ self.assertEqual(sm.resolve("XXX.ZZZ.x"), "root m2")
+
+ self.assertEqual(sm2.resolve("XXX.ZZZ.ZZZ"), 42)
+ self.assertEqual(sm2.resolve("XXX.ZZZ."), 42)
+ self.assertEqual(sm2.resolve("XXX.ZZZ.x"), "root m2")
+
def test_suite():
loader=TestLoader()
=== Removed File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/TestingServiceManager.py ===
=== Removed File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceDirective.py ===