[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests - __init__.py:1.2 testAddServiceContainer.py:1.2 testEditConfiguration.py:1.2 testServiceConfigURL.py:1.2 testServices.py:1.2

Jim Fulton jim@zope.com
Sat, 30 Nov 2002 13:39:48 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv12171/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests

Added Files:
	__init__.py testAddServiceContainer.py 
	testEditConfiguration.py testServiceConfigURL.py 
	testServices.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/Browser/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:39:48 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/__init__.py	Sat Nov 30 13:39:17 2002
@@ -0,0 +1,14 @@
+##############################################################################
+#
+# 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.
+# 
+##############################################################################
+


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testAddServiceContainer.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:39:48 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testAddServiceContainer.py	Sat Nov 30 13:39:17 2002
@@ -0,0 +1,215 @@
+##############################################################################
+#
+# 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 Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
+     import PlacefulSetup
+from Zope.ComponentArchitecture.GlobalServiceManager import defineService
+from Interface import Interface
+from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
+from Zope.ComponentArchitecture import getServiceManager
+from Zope.App.OFS.Services.ServiceManager.Browser.AddServiceConfiguration \
+     import AddServiceConfiguration
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.OFS.Services.ServiceManager.Browser.Adding import ComponentAdding
+from Zope.App.OFS.Services.ServiceManager.Browser.PackagesContents \
+     import PackagesContents
+
+from Zope.ComponentArchitecture import getService
+
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+
+from Zope.App.ZopePublication.TraversalViews.AbsoluteURL \
+     import AbsoluteURL, SiteAbsoluteURL
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.App.OFS.Content.Folder.RootFolder import IRootFolder
+from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
+from Zope.App.OFS.Container.IZopeContainer import IZopeContainer
+from Zope.App.OFS.Container.IContainer import IContainer
+from Zope.App.OFS.Container.ZopeContainerAdapter import ZopeContainerAdapter
+
+from Zope.App.OFS.Annotation.IAnnotatable import IAnnotatable
+from Zope.App.OFS.Annotation.IAttributeAnnotatable \
+     import IAttributeAnnotatable
+from Zope.App.OFS.Annotation.AttributeAnnotations import AttributeAnnotations
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.DependencyFramework.IDependable import IDependable
+from Zope.App.DependencyFramework.Dependable import Dependable
+
+from Zope.App.Traversing import traverse
+
+from Zope.ComponentArchitecture.GlobalViewService import provideView
+from Zope.ComponentArchitecture.GlobalViewService import setDefaultViewName
+
+from Zope.App.OFS.Services.ConfigurationInterfaces import IConfigurationStatus
+from Zope.App.OFS.Services.Browser.ConfigurationStatusWidget \
+     import ConfigurationStatusWidget
+
+from Zope.Schema.IField import IField, ITextLine, IText
+from Zope.App.Forms.Views.Browser.Widget import TextWidget, TextAreaWidget
+
+class I1(Interface): pass
+class C: __implements__ = IAttributeAnnotatable, I1
+
+class Test(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        provideAdapter(IContainer, IZopeContainer, ZopeContainerAdapter)
+        provideAdapter(IAttributeAnnotatable,
+                       IAnnotations, AttributeAnnotations)
+        provideAdapter(IAnnotatable, IDependable, Dependable)
+        self.buildFolders()
+
+        defineService('s1', I1)
+        self.folder1_1.setServiceManager(ServiceManager())
+
+        self.__Packages = traverse(
+            self.rootFolder, "folder1/folder1_1/++etc++Services/Packages")
+        self.__default = traverse(self.__Packages, 'default')
+
+        setDefaultViewName(IField, IBrowserPresentation, "widget")
+        provideView(IConfigurationStatus, "widget", IBrowserPresentation,
+                    ConfigurationStatusWidget)
+        provideView(ITextLine, "widget", IBrowserPresentation, TextWidget)
+        provideView(IText, "widget", IBrowserPresentation, TextAreaWidget)
+
+    def test_services(self):
+        
+        class I2(Interface): pass
+        class I3(Interface): pass
+        defineService('s2', I2)
+        defineService('s3', I3)
+        
+        request = TestRequest()
+        view = AddServiceConfiguration(
+            ComponentAdding(self.__default, request), request)
+
+        # We need the ContentAdding to have a contentName. It normally
+        # gets set during traversal, but we aren't traversing here.
+        view.context.contentName = 'sd1'
+
+        services = list(view.services())
+        services.sort()
+        self.failUnless((('s1' in services) and
+                         ('s2' in services) and
+                         ('s3' in services)), services) 
+
+    def test_components(self):
+
+        request = TestRequest(service_type='s1')
+        packages = self.__Packages
+        PackagesContents(packages, request).addPackage('p1')
+        PackagesContents(packages, request).addPackage('p2')
+
+        packages['default'].setObject('cd1', C())
+        packages['default'].setObject('cd2', C())
+        packages['p1'].setObject('c11', C())
+        packages['p2'].setObject('c21', C())
+        packages['p2'].setObject('c22', C())
+
+        view = AddServiceConfiguration(
+            ComponentAdding(self.__default, request), request)
+
+        # We need the ContentAdding to have a contentName. It normally
+        # gets set during traversal, but we aren't traversing here.
+        view.context.contentName = 'sd1'
+        
+        components = list(view.components())
+        components.sort()
+
+        self.assertEqual(
+            components,
+            ['/folder1/folder1_1/++etc++Services/Packages/default/cd1',
+             '/folder1/folder1_1/++etc++Services/Packages/default/cd2',
+             '/folder1/folder1_1/++etc++Services/Packages/p1/c11',
+             '/folder1/folder1_1/++etc++Services/Packages/p2/c21',
+             '/folder1/folder1_1/++etc++Services/Packages/p2/c22'])
+
+    def test_action_unregistered(self):
+        request = TestRequest()
+        self.__default.setObject('cd1', C())
+
+        view = AddServiceConfiguration(
+            ComponentAdding(self.__default, request), request)
+
+        # We need the ContentAdding to have a contentName. It normally
+        # gets set during traversal, but we aren't traversing here.
+        view.context.contentName = 'sd1'
+
+        view.action('s1',
+                    '/folder1/folder1_1/++etc++Services/Packages/default/cd1',
+                    )
+        self.assertRaises(ComponentLookupError,
+                          getService, self.folder1_1_1, 's1')
+
+    def test_action_active(self):
+        service = C()
+        self.__default.setObject('cd1', service)
+
+        request = TestRequest()
+        view = AddServiceConfiguration(
+            ComponentAdding(self.__default, request), request)
+
+        # We need the ContentAdding to have a contentName. It normally
+        # gets set during traversal, but we aren't traversing here.
+        view.context.contentName = 'sd1'
+
+        request.form["field.status"] = u"Active"
+
+        view.action('s1',
+                    '/folder1/folder1_1/++etc++Services/Packages/default/cd1')
+        self.assertEqual(getService(self.folder1_1_1, 's1'), service)
+
+    def test_action_register(self):
+        service = C()
+        self.__default.setObject('cd1', service)
+
+        request = TestRequest()
+        view = AddServiceConfiguration(
+            ComponentAdding(self.__default, request), request)
+
+        # We need the ContentAdding to have a contentName. It normally
+        # gets set during traversal, but we aren't traversing here.
+        view.context.contentName = 'sd1'
+
+        request.form["field.status"] = u"Active"
+
+        view.action('s1',
+                    '/folder1/folder1_1/++etc++Services/Packages/default/cd1')
+
+        view.context.contentName = 'sd2'
+
+        self.__default.setObject('cd2', C())
+
+        request.form["field.status"] = u"Registered"
+
+        view.action('s1',
+                    '/folder1/folder1_1/++etc++Services/Packages/default/cd2')
+
+
+        self.assertEqual(getService(self.folder1_1_1, 's1'), service)
+
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testEditConfiguration.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:39:48 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testEditConfiguration.py	Sat Nov 30 13:39:17 2002
@@ -0,0 +1,112 @@
+##############################################################################
+#
+# 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$
+"""
+__metaclass__ = type
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Interface import Interface
+from Zope.App.OFS.Services.ServiceManager.Browser.EditConfiguration \
+     import EditConfiguration
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.ComponentArchitecture.GlobalViewService import provideView
+from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
+from Zope.Publisher.Browser.BrowserView import BrowserView
+from Zope.Event.tests.PlacelessSetup import getEvents
+from Zope.Event.IObjectEvent import IObjectRemovedEvent, IObjectModifiedEvent
+from Zope.App.OFS.Container.IContainer import IContainer
+from Zope.App.OFS.Container.IZopeContainer import IZopeContainer
+from Zope.App.OFS.Container.ZopeContainerAdapter import ZopeContainerAdapter
+
+class Container(dict):
+    __implements__ = IContainer
+
+class I(Interface):
+    pass
+
+class C:
+    __implements__ = I
+
+
+class Test(PlacelessSetup, TestCase):
+
+    def test_remove_objects(self):
+
+        provideAdapter(IContainer, IZopeContainer, ZopeContainerAdapter)
+
+        c1 = C()
+        c2 = C()
+        c7 = C()
+        d = Container({'1': c1, '2': c2, '7': c7})
+
+        view = EditConfiguration(d, TestRequest())
+        view.remove_objects(['2', '7'])
+        self.assertEqual(d, {'1': c1})
+        
+        self.failUnless(
+            getEvents(IObjectRemovedEvent,
+                      filter = lambda event: event.object == c2),
+            )
+        self.failUnless(
+            getEvents(IObjectRemovedEvent,
+                      filter = lambda event: event.object == c7)
+            )
+        self.failUnless(
+            getEvents(IObjectModifiedEvent,
+                      filter = lambda event: event.object == d)
+            )
+
+    def test_configInfo(self):
+
+        class V(BrowserView):
+            def setPrefix(self, p):
+                self._prefix = p
+
+        provideView(I, 'ItemEdit', IBrowserPresentation, V)
+
+        c1 = C()
+        c2 = C()
+        c7 = C()
+        d = Container({'1': c1, '2': c2, '7': c7})
+
+        view = EditConfiguration(d, TestRequest())
+
+        info = view.configInfo()
+        self.assertEqual(len(info), 3)
+        self.assertEqual(info[0]['key'], '1')
+        self.assertEqual(info[1]['key'], '2')
+        self.assertEqual(info[2]['key'], '7')
+        self.assertEqual(info[0]['view'].__class__, V)
+        self.assertEqual(info[0]['view'].context, c1)
+        self.assertEqual(info[0]['view']._prefix, 'config1')
+        self.assertEqual(info[1]['view'].__class__, V)
+        self.assertEqual(info[1]['view'].context, c2)
+        self.assertEqual(info[1]['view']._prefix, 'config2')
+        self.assertEqual(info[2]['view'].__class__, V)
+        self.assertEqual(info[2]['view'].context, c7)
+        self.assertEqual(info[2]['view']._prefix, 'config7')
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testServiceConfigURL.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:39:48 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testServiceConfigURL.py	Sat Nov 30 13:39:17 2002
@@ -0,0 +1,70 @@
+##############################################################################
+#
+# 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 Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
+     import PlacefulSetup
+from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
+     import ServiceConfiguration
+from Zope.App.Traversing import traverse
+from Zope.Publisher.Browser.BrowserView import BrowserView
+from Zope.App.OFS.Services.ServiceManager.Browser.ServiceConfigURL \
+     import ServiceConfigURL
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+
+class V(BrowserView, ServiceConfigURL):
+    pass
+
+class C:
+    pass
+
+
+
+class Test(PlacefulSetup, TestCase):
+
+    def test(self):
+        self.buildFolders()
+        self.rootFolder.setServiceManager(ServiceManager())
+        default = traverse(
+            self.rootFolder,
+            '++etc++Services/Packages/default',
+            )
+        default.setObject('c', C())
+        traverse(default, 'configure').setObject(
+            '',
+            ServiceConfiguration('test_service',
+                                 '/++etc++Services/Packages/default/c')
+            )
+        config = traverse(default, 'configure/1')
+        view = V(config, TestRequest())
+        self.assertEqual(view.componentURL(),
+                         'http://127.0.0.1/++etc++Services/Packages/default/c')
+        
+        
+        
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testServices.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:39:48 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Browser/tests/testServices.py	Sat Nov 30 13:39:17 2002
@@ -0,0 +1,108 @@
+##############################################################################
+#
+# 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.App.OFS.Services.ServiceManager.Browser.Services import Services
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.ComponentArchitecture.GlobalViewService import provideView
+from Zope.Publisher.Browser.BrowserView import BrowserView
+
+
+class SM:
+
+    def __init__(self, **data):
+        self._data = data
+
+    def getBoundServiceTypes(self):
+        return self._data.keys()
+
+    def queryConfigurations(self, name):
+        return self._data[name]
+
+class I(Interface): pass
+
+class Registry:
+    __implements__ = I
+
+    def __init__(self, active):
+        self._active = active
+
+    def active(self):
+        return self._active
+
+
+class V(BrowserView):
+
+    _update = 0
+
+    def setPrefix(self, p):
+        self._prefix = p
+
+    def update(self):
+        self._update += 1
+
+class Test(PlacelessSetup, TestCase):
+
+    def test_update(self):
+        provideView(I, 'ChangeConfigurations', IBrowserPresentation, V)
+
+        r1 = Registry(None)
+        r2 = Registry(1)
+        r3 = Registry(1)
+
+        sm = SM(test1=r1, test2=r2, test3=r3)
+
+        services = Services(sm, TestRequest()).update()
+
+        self.assertEqual(len(services), 3)
+
+        self.assertEqual(services[0]['name'], 'test1')
+        self.assertEqual(services[0]['active'], False)
+        self.assertEqual(services[0]['inactive'], True)
+        self.assertEqual(services[0]['view'].context, r1)
+        self.assertEqual(services[0]['view']._prefix, "test1")
+        self.assertEqual(services[0]['view']._update, 1)
+
+        self.assertEqual(services[1]['name'], 'test2')
+        self.assertEqual(services[1]['active'], True)
+        self.assertEqual(services[1]['inactive'], False)
+        self.assertEqual(services[1]['view'].context, r2)
+        self.assertEqual(services[1]['view']._prefix, "test2")
+        self.assertEqual(services[1]['view']._update, 1)
+
+        self.assertEqual(services[2]['name'], 'test3')
+        self.assertEqual(services[2]['active'], True)
+        self.assertEqual(services[2]['inactive'], False)
+        self.assertEqual(services[2]['view'].context, r3)
+        self.assertEqual(services[2]['view']._prefix, "test3")
+        self.assertEqual(services[2]['view']._update, 1)
+        
+        
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')