[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests - testConfigurationManager.py:1.3 testServiceConfiguration.py:1.4 testServiceManager.py:1.5

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


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

Modified Files:
	testConfigurationManager.py testServiceConfiguration.py 
	testServiceManager.py 
Log Message:
Merge named-component-configuration-branch



=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testConfigurationManager.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testConfigurationManager.py:1.2	Sat Nov 30 13:39:18 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testConfigurationManager.py	Thu Dec 12 06:32:33 2002
@@ -2,14 +2,14 @@
 #
 # 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$
@@ -22,12 +22,28 @@
 from unittest import TestCase, TestSuite, main, makeSuite
 from Interface.Common.tests.BaseTestMapping import BaseTestIEnumerableMapping
 from Interface.Verify import verifyObject
+from Zope.App.OFS.Container.IDeleteNotifiable import IDeleteNotifiable
+from Zope.App.OFS.Container.IContainer import IContainer
+from Zope.App.OFS.Container.IZopeContainer import IZopeContainer
+from Zope.App.OFS.Container.ZopeContainerAdapter import ZopeContainerAdapter
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
+from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
 
-class Test(BaseTestIEnumerableMapping, TestCase):
+
+class Undeletable:
+
+    __implements__ = IDeleteNotifiable
+
+    def manage_beforeDelete(self, object, container):
+        self.was_called = 1
+
+
+class Test(BaseTestIEnumerableMapping, PlacelessSetup, TestCase):
 
     """Testing for Configuration Manager """
 
     def setUp(self):
+        PlacelessSetup.setUp(self)
         self.__manager = manager = ConfigurationManager()
         for l in 'abcdefghijklmnop':
             manager.setObject('', l)
@@ -36,7 +52,7 @@
 
     def test_implements_IConfigurationManager(self):
         verifyObject(IConfigurationManager, self.__manager)
-      
+
     def _IEnumerableMapping__stateDict(self):
         # Hook needed by BaseTestIEnumerableMapping
         # also, effectively test setObject and __delitem__.
@@ -63,10 +79,10 @@
         self.__manager.moveTop([])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -74,10 +90,10 @@
         self.__manager.moveTop(['1'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -85,10 +101,10 @@
         self.__manager.moveTop(['1', '88', '3', '2', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -96,10 +112,10 @@
         self.__manager.moveTop(['3'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['3', '1', '2', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -107,10 +123,10 @@
         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', 
+            ['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()
 
@@ -119,7 +135,7 @@
         manager.setObject('', 'a')
         manager.moveTop(['1'])
         self.assertEqual(list(manager.items()), [('1', 'a')])
-                              
+
     #########################################################
     # Move Bottom
 
@@ -127,10 +143,10 @@
         self.__manager.moveBottom([])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -138,10 +154,10 @@
         self.__manager.moveBottom(['16'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -149,10 +165,10 @@
         self.__manager.moveBottom(['14', '88', '16', '15', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -160,10 +176,10 @@
         self.__manager.moveBottom(['3'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -172,10 +188,10 @@
             ['1', '3', '88', '4', '11', '16', '15', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['2', '5', '6', '7', '9', 
+            ['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()
 
@@ -184,18 +200,18 @@
         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', 
+            ['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()
 
@@ -203,10 +219,10 @@
         self.__manager.moveUp(['1'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -214,10 +230,10 @@
         self.__manager.moveUp(['1', '88', '3', '2', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -225,10 +241,10 @@
         self.__manager.moveUp(['3'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '3', '2', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -237,10 +253,10 @@
             ['1', '3', '88', '4', '11', '16', '15', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '3', '4', '2', '5', '6', '7', '11', '9', 
+            ['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()
 
@@ -249,18 +265,18 @@
         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', 
+            ['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()
 
@@ -268,10 +284,10 @@
         self.__manager.moveDown(['16'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -279,10 +295,10 @@
         self.__manager.moveDown(['16', '88', '14', '15', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9', 
+            ['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()
 
@@ -290,10 +306,10 @@
         self.__manager.moveDown(['3'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '4', '3', '5', '6', '7', '9', 
+            ['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()
 
@@ -302,10 +318,10 @@
             ['1', '3', '88', '4', '11', '16', '15', '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['2', '1', '5', '3', '4', '6', '7', '9', 
+            ['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()
 
@@ -314,9 +330,18 @@
         manager.setObject('', 'a')
         manager.moveDown(['1'])
         self.assertEqual(list(manager.items()), [('1', 'a')])
-                              
-        
-        
+
+    #########################################################
+
+    def test_manageBeforeDelete(self):
+        provideAdapter(IContainer, IZopeContainer, ZopeContainerAdapter)
+        container = []
+        manager = ConfigurationManager()
+        thingy = Undeletable()
+        manager.setObject('xyzzy', thingy)
+        manager.manage_beforeDelete(manager, container)
+        self.failUnless(thingy.was_called)
+
 
 def test_suite():
     return makeSuite(Test)


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceConfiguration.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceConfiguration.py:1.3	Thu Dec  5 12:00:44 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceConfiguration.py	Thu Dec 12 06:32:33 2002
@@ -70,7 +70,7 @@
         self._dependents = tuple(
             [d for d in self._dependents if d != location]
             )
-        
+
     def dependents(self):
         return self._dependents
 
@@ -93,14 +93,11 @@
 
         self.__c = traverse(default, 'c')
         self.__cm = ZopeContainerAdapter(traverse(default, "configure"))
-        
+
         self.__cm.setObject('', configuration)
 
         self.__config = traverse(default, 'configure/1')
 
-    def test_getComponent(self):
-        self.assertEqual(self.__config.getComponent(), self.__c)
-
     def test_activated(self):
         old = self.__c._bound
         self.__config.activated()
@@ -111,6 +108,15 @@
         self.__config.deactivated()
         self.assertEqual(self.__c._unbound, old+('test_service',))
 
+    def test_getInterface(self):
+        self.assertEquals(self.__config.getInterface(), ITestService)
+
+    # XXX the following tests check the same things as
+    # Zope.App.OFS.Services.tests.testConfigurations, but in a different way
+
+    def test_getComponent(self):
+        self.assertEqual(self.__config.getComponent(), self.__c)
+
     def test_manage_afterAdd(self):
         self.assertEqual(self.__c._dependents,
                          ('/++etc++Services/Packages/default/configure/1', ))
@@ -135,7 +141,7 @@
             pass # OK
         else:
             self.failUnless(0, "Should have gotten a depency error")
-            
+
 
 def test_suite():
     return makeSuite(Test)


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.py:1.4	Sat Nov 30 13:39:18 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/testServiceManager.py	Thu Dec 12 06:32:33 2002
@@ -2,14 +2,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.
-# 
+#
 ##############################################################################
 """
 
@@ -59,7 +59,7 @@
         self.createServiceManager()
         sm = traverse(self.rootFolder, '++etc++Services')
         default = traverse(sm, 'Packages/default')
-        
+
         ts = TestService()
         default.setObject('test_service1', ts)
         configuration = ServiceConfiguration(
@@ -109,9 +109,9 @@
 
         sm = traverse(self.rootFolder, '++etc++Services')
         traverse(sm, 'Packages/default/configure/1').status = Unregistered
-        
+
         self.assertEqual(getService(self.rootFolder, 'test_service'), root_ts)
-    
+
     def testContextServiceLookup(self):
         self.testGetService() # set up localservice
         sm=getServiceManager(self.rootFolder)
@@ -124,14 +124,14 @@
 
         self.folder1.setServiceManager(ServiceManager())
         sm2=getServiceManager(self.folder1)
-        
+
         self.assertEqual(getService(self.folder1, 'test_service'),
                          sm.Packages['default']['test_service1'])
 
     def testComponentArchitectureServiceLookup(self):
         self.rootFolder.setServiceManager(ServiceManager())
         self.folder1.setServiceManager(ServiceManager())
-        
+
         ts = TestService()
 
         globsm=getServiceManager(None)
@@ -145,7 +145,7 @@
         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')
@@ -180,16 +180,16 @@
         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()
     return loader.loadTestsFromTestCase(ServiceManagerTests)