[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser/tests - testComponentConfigURL.py:1.2 testNameConfigurableView.py:1.2

Marius Gedminas mgedmin@codeworks.lt
Thu, 12 Dec 2002 06:33:02 -0500


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

Added Files:
	testComponentConfigURL.py testNameConfigurableView.py 
Log Message:
Merge named-component-configuration-branch



=== Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testComponentConfigURL.py 1.1 => 1.2 ===
--- /dev/null	Thu Dec 12 06:33:01 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testComponentConfigURL.py	Thu Dec 12 06:32:31 2002
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Tests for ComponentConfigURL
+
+$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.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.OFS.Services.Browser.ComponentConfigURL import ComponentConfigURL
+from Zope.Security.Proxy import Proxy
+from Zope.Security.Checker import selectChecker
+
+class V(BrowserView, ComponentConfigURL):
+    pass
+
+class C:
+    pass
+
+class ContextStub:
+
+    def __init__(self, path):
+        self.componentPath = path
+
+
+class TestComponentConfigURL(PlacefulSetup, TestCase):
+
+    # XXX reduce dependencies on ServiceManager package
+
+    def test_componentURL(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_componentPath(self):
+        context = ContextStub('/path/to/me')
+        view = V(context, TestRequest())
+        self.assertEqual(view.componentPath(), '/path/to/me')
+
+        context = ContextStub(('', 'path', 'to', 'me'))
+        view = V(context, TestRequest())
+        self.assertEqual(view.componentPath(), '/path/to/me')
+
+        path = ('', 'path', 'to', 'me')
+        wrapped_path = Proxy(path, selectChecker(path))
+        context = ContextStub(wrapped_path)
+        view = V(context, TestRequest())
+        self.assertEqual(view.componentPath(), '/path/to/me')
+
+
+def test_suite():
+    return TestSuite((
+        makeSuite(TestComponentConfigURL),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testNameConfigurableView.py 1.1 => 1.2 ===
--- /dev/null	Thu Dec 12 06:33:01 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testNameConfigurableView.py	Thu Dec 12 06:32:31 2002
@@ -0,0 +1,129 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Unit test for the generic NameConfigurable view mixin
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Interface import Interface
+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
+from Zope.App.OFS.Services.Browser.NameConfigurableView \
+     import NameConfigurableView
+from Zope.App.Traversing.ITraversable import ITraversable
+
+
+class SM:
+
+    def __init__(self, **data):
+        self._data = data
+
+    def listConfigurationNames(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 ITestConfiguration(Interface): pass
+
+class Configuration:
+
+    __implements__ = ITestConfiguration, ITraversable
+
+    def __init__(self, path):
+        self.componentPath = path
+
+    def traverse(self, name, parameters, original_name, furtherPath):
+        return self
+
+class V(BrowserView):
+
+    _update = 0
+
+    def setPrefix(self, p):
+        self._prefix = p
+
+    def update(self):
+        self._update += 1
+
+class AU(BrowserView):
+
+    def __str__(self):
+        return "/" + self.context.componentPath
+
+class Test(PlacelessSetup, TestCase):
+
+    def test_update(self):
+        provideView(I, 'ChangeConfigurations', IBrowserPresentation, V)
+        provideView(ITestConfiguration, 'absolute_url', IBrowserPresentation,
+                    AU)
+
+        r1 = Registry(None)
+        r2 = Registry(Configuration('1'))
+        r3 = Registry(Configuration('1'))
+
+        sm = SM(test1=r1, test2=r2, test3=r3)
+
+        services = NameConfigurableView(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[0]['url'], None)
+
+        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[1]['url'], '/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)
+        self.assertEqual(services[2]['url'], '/1')
+
+
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')