[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_servicemanager.py:1.16 test_serviceregistration.py:1.2 test_utility.py:1.11 test_view.py:1.23

Jim Fulton jim at zope.com
Sun Sep 21 13:33:26 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv15302/src/zope/app/services/tests

Modified Files:
	test_servicemanager.py test_serviceregistration.py 
	test_utility.py test_view.py 
Log Message:
No-longer use context wrappers.

Use helper function to add registrations.

Changed to use __setitem__ rather than setObject


=== Zope3/src/zope/app/services/tests/test_servicemanager.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/services/tests/test_servicemanager.py:1.15	Tue Sep  2 16:46:51 2003
+++ Zope3/src/zope/app/services/tests/test_servicemanager.py	Sun Sep 21 13:33:25 2003
@@ -19,7 +19,6 @@
 from unittest import TestCase, TestLoader, TextTestRunner
 
 from zope.interface import Interface, implements
-from zope.context import getWrapperContainer
 from zope.app.services.service import ServiceManager
 from zope.app.services.service import ServiceRegistration
 from zope.component import getService, getServiceManager
@@ -48,18 +47,21 @@
         default = traverse(sm, 'default')
 
         ts = TestService()
-        default.setObject('test_service1', ts)
+        default['test_service1'] = ts
         registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service1')
 
-        default.getRegistrationManager().setObject('', registration)
-        traverse(default.getRegistrationManager(), '1').status = ActiveStatus
+        rm = default.getRegistrationManager()
+        name = rm.addRegistration(registration)
+        traverse(rm, name).status = ActiveStatus
 
         testOb = getService(self.rootFolder, 'test_service')
-        c = getWrapperContainer
-        self.assertEqual(c(c(c(testOb))), self.rootFolder)
+        self.assertEqual(testOb.__parent__.__parent__.__parent__,
+                         self.rootFolder)
         self.assertEqual(testOb, ts)
+        # used by one of the callers
+        return name
 
     def test_queryLocalService(self):
         sm = traverse(self.rootFolder, '++etc++site')
@@ -74,23 +76,24 @@
         # Test found local
         default = traverse(sm, 'default')
         ts = TestService()
-        default.setObject('test_service1', ts)
+        default['test_service1'] = ts
         registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service1')
-        default.getRegistrationManager().setObject('', registration)
-        traverse(default.getRegistrationManager(), '1').status = ActiveStatus
+        rm = default.getRegistrationManager()
+        name = rm.addRegistration(registration)
+        traverse(rm, name).status = ActiveStatus
 
         testOb = sm.queryLocalService('test_service')
-        c = getWrapperContainer
-        self.assertEqual(c(c(c(testOb))), self.rootFolder)
+        self.assertEqual(testOb.__parent__.__parent__.__parent__,
+                         self.rootFolder)
         self.assertEqual(testOb, ts)
 
 
     def test_get(self):
         sm = traverse(self.rootFolder, '++etc++site')
         default = sm.get('default')
-        self.assertEqual(default, sm.Packages['default'])
+        self.assertEqual(default, sm['default'])
         self.assertEqual(sm.get('spam'), None)
 
     def testAddService(self):
@@ -98,21 +101,21 @@
         default = traverse(sm, 'default')
 
         ts1 = TestService()
-        default.setObject('test_service1', ts1)
+        default['test_service1'] = ts1
         registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service1')
-        default.getRegistrationManager().setObject('', registration)
-        traverse(default.getRegistrationManager(), '1').status = ActiveStatus
+        rm = default.getRegistrationManager()
+        name = rm.addRegistration(registration)
+        traverse(rm, name).status = ActiveStatus
 
         ts2 = TestService()
-        default.setObject('test_service2', ts2)
+        default['test_service2'] = ts2
         registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service2')
-        default.getRegistrationManager().setObject('', registration)
-        traverse(default.getRegistrationManager(), '2'
-                 ).status = RegisteredStatus
+        name = rm.addRegistration(registration)
+        traverse(rm, name).status = RegisteredStatus
 
         testOb = getService(self.rootFolder, 'test_service')
         self.assertEqual(testOb, ts1)
@@ -124,17 +127,17 @@
         gsm = getServiceManager(None)
         gsm.provideService('test_service', root_ts)
 
-        self.testGetService() # set up localservice
+        name = self.testGetService() # set up localservice
 
         sm = traverse(self.rootFolder, '++etc++site')
         cm = traverse(sm, 'default').getRegistrationManager()
-        traverse(cm, '1').status = UnregisteredStatus
+        traverse(cm, name).status = UnregisteredStatus
 
         self.assertEqual(getService(self.rootFolder, 'test_service'), root_ts)
 
     def testContextServiceLookup(self):
         self.testGetService() # set up localservice
-        sm=getServiceManager(self.rootFolder)
+        sm = getServiceManager(self.rootFolder)
         self.assertEqual(getService(self.folder1_1, 'test_service'),
                          sm['default']['test_service1'])
 
@@ -163,29 +166,27 @@
         # XXX This test expects that the local module implementation
         # (the Manager class) to register itself.  This is no longer
         # intentional behavior; the right tests need to be determined.
-        from zope.app.context import ContextWrapper as cw
         from zope.app.services.module import Manager
         import zope.app.services.tests.sample1
         import zope.app.services.tests.sample2
 
         sm = self.makeSite()
 
-        default = cw(sm['default'], self.rootFolder, name='default')
-        default.setObject('m1', Manager('zope.app.services.tests.sample1',
-                                        'x = "root m1"\n'))
-        manager = cw(default['m1'], default, name='m1')
+        default = contained(sm['default'], self.rootFolder, name='default')
+        default['m1'] = Manager('zope.app.services.tests.sample1',
+                                'x = "root m1"\n')
+        manager = contained(default['m1'], default, name='m1')
         manager.execute()
-        default.setObject('m2', Manager('XXX.ZZZ',
-                                        'x = "root m2"\nZZZ = 42\n'))
-        manager = cw(default['m2'], default, name='m2')
+        default['m2'] = Manager('XXX.ZZZ', 'x = "root m2"\nZZZ = 42\n')
+        manager = contained(default['m2'], default, name='m2')
         manager.execute()
 
-        self.folder1.setSiteManager(ServiceManager())
+        self.folder1.setSiteManager(ServiceManager(self.folder1))
         sm2=getServiceManager(self.folder1)
-        default = cw(sm2['default'], self.folder1, name='default')
-        default.setObject('m1', Manager('zope.app.services.tests.sample1',
-                                        'x = "folder1 m1 1"'))
-        manager = cw(default['m1'], default, name='m1')
+        default = contained(sm2['default'], self.folder1, name='default')
+        default['m1'] = Manager('zope.app.services.tests.sample1',
+                                'x = "folder1 m1 1"')
+        manager = contained(default['m1'], default, name='m1')
         manager.execute()
 
         self.assertEqual(


=== Zope3/src/zope/app/services/tests/test_serviceregistration.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/services/tests/test_serviceregistration.py:1.1	Sat Jun 21 17:22:13 2003
+++ Zope3/src/zope/app/services/tests/test_serviceregistration.py	Sun Sep 21 13:33:25 2003
@@ -36,7 +36,6 @@
 from zope.app.interfaces.dependable import IDependable
 from zope.app.interfaces.dependable import DependencyError
 
-
 class ITestService(Interface):
     pass
 
@@ -82,8 +81,7 @@
                            '++etc++site/default')
         self.__default = default
 
-        default.setObject('c', TestService())
-
+        default['c'] = TestService()
 
         registration = ServiceRegistration(
             'test_service', '/++etc++site/default/c')
@@ -91,9 +89,9 @@
         self.__c = traverse(default, 'c')
         self.__cm = default.getRegistrationManager()
 
-        self.__cm.setObject('', registration)
+        self.__registration_name = self.__cm.addRegistration(registration)
 
-        self.__config = traverse(default.getRegistrationManager(), '1')
+        self.__config = traverse(self.__cm, self.__registration_name)
         self.__configpath = getPath(self.__config)
 
     def test_activated(self):
@@ -115,21 +113,21 @@
     def test_getComponent(self):
         self.assertEqual(self.__config.getComponent(), self.__c)
 
-    def test_afterAddHook(self):
+    def test_addNotify(self):
         self.assertEqual(self.__c._dependents,
                          (self.__configpath, ))
         u = getAdapter(self.__c, IRegistered)
         self.assertEqual(list(u.usages()),
                          [self.__configpath])
 
-    def test_beforeDeleteHook_and_unregistered(self):
+    def test_removeNotify_and_unregistered(self):
         self.__config.status = RegisteredStatus
 
         sm = getServiceManager(self.__default)
         registry = sm.queryRegistrationsFor(self.__config)
         self.failUnless(registry, "The components should be registered")
 
-        del self.__cm['1']
+        del self.__cm[self.__registration_name]
         self.assertEqual(self.__c._dependents, ())
         u = getAdapter(self.__c, IRegistered)
         self.assertEqual(len(u.usages()), 0)
@@ -139,15 +137,15 @@
     def test_disallow_delete_when_active(self):
         self.__config.status = ActiveStatus
         try:
-            del self.__cm['1']
+            del self.__cm[self.__registration_name]
         except DependencyError:
             pass # OK
         else:
-            self.failUnless(0, "Should have gotten a depency error")
+            self.fail("Should have gotten a dependency error")
 
     def test_not_a_local_service(self):
         defineService('test_service_2', ITestService)
-        self.__default.setObject('c2', TestServiceBase())
+        self.__default['c2'] = TestServiceBase()
 
         self.assertRaises(
             TypeError,


=== Zope3/src/zope/app/services/tests/test_utility.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/services/tests/test_utility.py:1.10	Wed Aug  6 09:03:21 2003
+++ Zope3/src/zope/app/services/tests/test_utility.py	Sun Sep 21 13:33:25 2003
@@ -34,7 +34,6 @@
 from zope.app.interfaces.services.utility import ILocalUtility
 from zope.app.interfaces.services.registration import IRegistered
 from zope.app.interfaces.dependable import IDependable
-from zope.context import getWrapperContainer
 from zope.app.tests import setup
 
 class IFo(Interface): pass
@@ -141,7 +140,7 @@
     def test_registrationsFor_methods(self):
         utilities = getService(self.rootFolder, "Utilities")
         default = traverse(self.rootFolder, "++etc++site/default")
-        default.setObject('foo', Foo("local"))
+        default['foo'] = Foo("local")
         path = "/++etc++site/default/foo"
 
         for name in ('', 'bob'):
@@ -161,13 +160,13 @@
 
         utilities = getService(self.rootFolder, "Utilities")
         default = traverse(self.rootFolder, "++etc++site/default")
-        default.setObject('foo', Foo("local"))
+        default['foo'] = Foo("local")
         path = "/++etc++site/default/foo"
         cm = default.getRegistrationManager()
 
         for name in ('', 'bob'):
             registration = utility.UtilityRegistration(name, IFoo, path)
-            cname = cm.setObject('', registration)
+            cname = cm.addRegistration(registration)
             registration = traverse(cm, cname)
 
             gout = name and "foo global "+name or "foo global"
@@ -194,8 +193,8 @@
         cr2 = utilities.queryRegistrationsFor(
             utility.UtilityRegistration("bob", IFoo, path))
         self.assertEqual(r, [(IFoo, "", cr1), (IFoo, "bob", cr2)])
-        self.assertEqual(getWrapperContainer(r[0][2]), utilities)
-        self.assertEqual(getWrapperContainer(r[1][2]), utilities)
+        self.assertEqual(r[0][2].__parent__, utilities)
+        self.assertEqual(r[1][2].__parent__, utilities)
         # Now test that an empty registry doesn't show up
         for cd in cr1.info(): # Remove everything from cr1
             cd['registration'].status = UnregisteredStatus


=== Zope3/src/zope/app/services/tests/test_view.py 1.22 => 1.23 ===
--- Zope3/src/zope/app/services/tests/test_view.py:1.22	Tue Sep  2 16:46:51 2003
+++ Zope3/src/zope/app/services/tests/test_view.py	Sun Sep 21 13:33:25 2003
@@ -21,8 +21,7 @@
 from zope.interface import Interface, directlyProvides, implements
 from zope.interface.verify import verifyObject
 
-from zope.app.content.folder import RootFolder
-from zope.app.context import ContextWrapper
+from zope.app.content.folder import rootFolder
 from zope.app.interfaces.services.view import IZPTTemplate
 from zope.app.services.service import ServiceManager
 from zope.app.services.servicenames import Views
@@ -44,6 +43,7 @@
 
 from zope.publisher.browser import TestRequest
 from zope.publisher.interfaces.browser import IBrowserPresentation
+from zope.app.container.contained import contained
 
 class I1(Interface):
     pass
@@ -99,7 +99,7 @@
 
 
     def createTestingRegistry(self):
-        return ContextWrapper(ViewService(), C())
+        return contained(ViewService(), C())
 
     def createTestingRegistration(self):
         return Registration()
@@ -131,7 +131,7 @@
         sm = traverse(self.rootFolder, '++etc++site')
 
         registration_manager = traverse(sm, 'default').getRegistrationManager()
-        key = registration_manager.setObject('', Registration())
+        key = registration_manager.addRegistration(Registration())
         registration = traverse(registration_manager, key)
 
         class O:
@@ -162,8 +162,8 @@
         sm = self.buildFolders(site=True)
         registration_manager = traverse(sm, 'default').getRegistrationManager()
         registration = Registration()
-        registration_manager.setObject('', registration)
-        registration = traverse(registration_manager, '1')
+        name = registration_manager.addRegistration(registration)
+        registration = traverse(registration_manager, name)
 
         class O:
             implements(I1)
@@ -209,12 +209,12 @@
         raise ImportError(name)
 
 
-class TestViewRegistration(TestCase):
+class TestViewRegistration(PlacefulSetup, TestCase):
 
     def test_getView(self):
         folder = ModuleFinder()
-        folder = ContextWrapper(folder, folder)
-        registration = ContextWrapper(
+        folder = contained(folder, folder)
+        registration = contained(
             ViewRegistration(I1, 'test', IBrowserPresentation, "Foo.Bar.A",
                               'zope.View'),
             folder,
@@ -234,16 +234,16 @@
 
     def setUp(self):
         PlacefulSetup.setUp(self)
-        self.rootFolder = RootFolder()
-        self.rootFolder.setSiteManager(PhonyServiceManager())
+        self.rootFolder = rootFolder()
+        self.rootFolder.setSiteManager(PhonyServiceManager(self.rootFolder))
         default = traverse(self.rootFolder, '++etc++site/default')
         self.__template = PhonyTemplate()
-        default.setObject('t', self.__template)
-        self.folder = ContextWrapper(ModuleFinder(), self.rootFolder)
-        self.folder = ContextWrapper(ModuleFinder(), self.folder)
+        default['t'] = self.__template
+        self.folder = contained(ModuleFinder(), self.rootFolder)
+        self.folder = contained(ModuleFinder(), self.folder)
 
     def test_getView_template(self):
-        registration = ContextWrapper(
+        registration = contained(
             PageRegistration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
                               template='/++etc++site/default/t',
@@ -265,7 +265,7 @@
         self.assertEqual(registration.presentationType, I2)
 
     def test_getView_attribute(self):
-        registration = ContextWrapper(
+        registration = contained(
             PageRegistration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
                               attribute='run',
@@ -278,7 +278,7 @@
         self.assertEquals(view, A.run)
 
     def test_getView_errors(self):
-        registration = ContextWrapper(
+        registration = contained(
             PageRegistration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
                               ),




More information about the Zope3-Checkins mailing list