[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Views/Browser/tests - __init__.py:1.2 testAdder.py:1.2 testBindings.py:1.2 testContents.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:28:44 -0400


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

Added Files:
	__init__.py testAdder.py testBindings.py testContents.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Views/Browser/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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/Views/Browser/tests/testAdder.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.App.OFS.Container.Views.Browser.tests.AdderBaseTests \
+     import BaseRegistryTest, BaseAddingTest
+from Zope.App.OFS.Services.AddableService.tests.AddableSetup import \
+  AddableSetup
+from Zope.ComponentArchitecture import getServiceManager
+
+class Methods(AddableSetup):
+    # Supply the methods needed by the bases.
+
+    def _TestView__newContext(self):
+        from Zope.App.OFS.Services.ServiceManager.ServiceManager \
+             import ServiceManager
+        return ServiceManager()
+
+    def _TestView__newView(self, container):
+        from Zope.App.OFS.Services.ServiceManager.Views.Browser.Adder \
+             import Adder 
+        return Adder(container, None)
+
+    def _TestAdderView__registry(self):
+        return 'AddableServices'
+
+
+class RegistryTest(Methods, BaseRegistryTest, TestCase): pass
+class AddingTest(Methods, BaseAddingTest, TestCase):
+    def setUp(self):
+        Methods.setUp(self)
+        BaseAddingTest.setUp(self)
+
+def test_suite():
+    return TestSuite([makeSuite(RegistryTest),
+                      makeSuite(AddingTest),
+                      ])
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Views/Browser/tests/testBindings.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+from unittest import TestCase, TestSuite, main, makeSuite
+from Interface import Interface
+
+from Zope.App.OFS.Services.ServiceManager.Views.Browser.Bindings \
+    import Bindings
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup import \
+    PlacefulSetup
+from Zope.ComponentArchitecture import getService, getServiceManager
+
+class ITestService1(Interface): pass
+class ITestService2(Interface): pass
+
+class TestService1:
+
+    __implements__ = ITestService1
+
+class TestService2:
+
+    __implements__ = ITestService2
+
+
+class ServiceManagerTests(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        self.buildFolders()
+        self.createServiceManager()
+        self.sm=getServiceManager(self.rootFolder)
+        getServiceManager(None).defineService('service1', ITestService1)
+        getServiceManager(None).defineService('service2', ITestService2)
+
+        sA = TestService1()
+        sB = TestService1()
+        sC = TestService2()
+
+        self.sm.setObject('TestServiceA', sA)
+        self.sm.setObject('TestServiceB', sB)
+        self.sm.setObject('TestServiceC', sC)
+
+        self.sm.bindService('service1', 'TestServiceA')
+
+    def testGetServicesTable(self):
+        view = Bindings(self.sm, None)
+        self.assertEqual(len(view.getServicesTable()), 8) #that is, 2+6
+
+    def testServiceTableBound(self):
+        view = Bindings(self.sm, None)
+        services = view.getServicesTable()
+        serviceMap = None
+        for sMap in services:
+            if sMap['name'] == 'service1':
+                serviceMap = sMap
+                break
+            
+        self.assertEqual(serviceMap['bound'], 'TestServiceA')
+
+## XXX Was commented:
+## """This test is not working (bug in getServicesTable(), returning
+## 'Acquired' instead of 'None'"""
+##
+## Then further commented:
+## However, we're now acquiring from the globally defined services,
+## so it is appropriate to return 'Acquired'.
+##
+## To which I now add:
+## I actually think that it should be 'None' after all.  Where is
+## service2 provided globally?
+##        
+    def testServiceTableNone(self):
+        view = Bindings(self.sm, None)
+        services = view.getServicesTable()
+        serviceMap = None
+        for sMap in services:
+            if sMap['name'] == 'service2':
+                serviceMap = sMap
+                break
+        self.assertEqual(serviceMap['bound'], 'None')
+
+def test_suite():
+    return TestSuite([makeSuite(ServiceManagerTests)])
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/Views/Browser/tests/testContents.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+
+from Interface import Interface
+from Zope.App.OFS.Services.ServiceManager.Views.Browser.Contents \
+     import ServiceManagerContents
+from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
+from Zope.App.OFS.Container.Views.Browser.tests.testContents \
+     import BaseTestContentsBrowserView
+
+class IDummy(Interface):
+    pass
+
+class Dummy:
+    __implements__ = IDummy
+    
+class Test(BaseTestContentsBrowserView, unittest.TestCase):
+
+    def _TestView__newContext(self):
+        return ServiceManager()
+
+    def _TestView__newView(self, container):
+        return ServiceManagerContents(container, None)
+
+    def testExtractContents(self):
+        """ Does _extractContents return the correct information? """
+
+        smc = ServiceManagerContents(None , None)
+        info = smc._extractContentInfo(('dummy', Dummy(),))
+
+        self.assert_('IDummy' in info['interfaces'])
+
+    def testInfo(self):
+        """ Do we get the correct information back from
+            ServiceManagerContents?
+        """
+
+        sm = ServiceManager()
+        dummy = Dummy()
+        sm.setObject('dummy', dummy)
+
+        smc = ServiceManagerContents(sm, None)
+        info_list = smc.listContentInfo()
+
+        self.assertEquals(len(info_list), 1)
+
+        interfaces = [ x['interfaces'] for x in info_list ]
+        self.assert_('IDummy' in interfaces[0])
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.main()