[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests - EventSetup.py:1.6 testEventService.py:1.6

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


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

Modified Files:
	EventSetup.py testEventService.py 
Log Message:
Updated to reflect new configuration framework.



=== Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/EventSetup.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/EventSetup.py:1.5	Fri Oct  4 14:37:20 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/EventSetup.py	Sat Nov 30 13:37:17 2002
@@ -16,68 +16,47 @@
 Revision information:
 $Id$
 """
+
 from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
   import PlacefulSetup
-from Zope.ComponentArchitecture import getService, getServiceManager
-
-from Zope.App.Traversing.Traverser import Traverser
-from Zope.App.Traversing.ITraverser import ITraverser
-from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
-from Zope.App.Traversing.ITraversable import ITraversable
-
-
-from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
-from Zope.App.Traversing.IContainmentRoot import IContainmentRoot
-from Zope.App.Traversing.PhysicalLocationAdapters \
-     import WrapperPhysicallyLocatable, RootPhysicallyLocatable
 
+from Zope.App.OFS.Services.ServiceManager.ServiceManager \
+     import ServiceManager
 
-from Zope.App.OFS.Container.ContainerTraversable import ContainerTraversable
-from Zope.App.OFS.Container.IContainer import ISimpleReadContainer
+from Zope.App.OFS.Services.LocalEventService.LocalEventService \
+     import LocalEventService
 
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
+     import ServiceConfiguration
 
+from Zope.App.Traversing import getPhysicalPathString, traverse
 
-from Zope.App.OFS.Services.LocalEventService.LocalEventService \
-     import LocalEventService
-from Zope.App.OFS.Services.ServiceManager.ServiceDirective \
-     import ServiceDirective
-from Zope.App.Traversing import getPhysicalPathString
+from Zope.App.OFS.Services.ConfigurationInterfaces import Active
 
 class EventSetup(PlacefulSetup):
     
     def setUp(self):
         PlacefulSetup.setUp(self)
         self.buildFolders()
-        adapterService = getService(None, "Adapters")
-        adapterService.provideAdapter(
-            None, ITraverser, Traverser)
-        adapterService.provideAdapter(
-            None, ITraversable, DefaultTraversable)
-        adapterService.provideAdapter(
-            ISimpleReadContainer, ITraversable, ContainerTraversable)
-
-        adapterService.provideAdapter(
-              None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
-        adapterService.provideAdapter(
-              IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
-
-        from Zope.App.Traversing.Namespaces import provideNamespaceHandler
-        from Zope.App.Traversing.EtcNamespace import etc
-        provideNamespaceHandler('etc', etc)
-        
         self.createEventService()
-    
-    def createEventService(self, folder=None):
-        if folder is None: folder=self.rootFolder
+
+    def createServiceManager(self, folder):
+        folder.setServiceManager(ServiceManager())
+
+    def createEventService(self, path=None):
+
+        folder = self.rootFolder
+        if path is not None:
+            folder = traverse(folder, path)
+
         if not folder.hasServiceManager():
             self.createServiceManager(folder)
-        sm=getServiceManager(folder) # wrapped now
-        sm.Packages['default'].setObject("myEventService",LocalEventService())
 
-        path = "%s/Packages/default/myEventService" % getPhysicalPathString(sm)
-        directive = ServiceDirective("Events", path)
-        sm.Packages['default'].setObject("myEventServiceDir", directive)
-        sm.bindService(directive)
+        sm = traverse(folder, '++etc++Services')
+        default = traverse(sm, 'Packages/default')
+        default.setObject("myEventService", LocalEventService())
 
-        
-    
+        path = "%s/Packages/default/myEventService" % getPhysicalPathString(sm)
+        configuration = ServiceConfiguration("Events", path)
+        default['configure'].setObject("myEventServiceDir", configuration)
+        traverse(default, 'configure/1').status = Active


=== Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py:1.5	Thu Oct  3 16:53:21 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/tests/testEventService.py	Sat Nov 30 13:37:17 2002
@@ -19,19 +19,20 @@
 
 from unittest import TestCase, TestLoader, TextTestRunner
 
-from Zope.ComponentArchitecture import getService, getServiceManager
-
-from Zope.Proxy.ContextWrapper import ContextWrapper
-
-from Zope.Exceptions import NotFoundError
+from Zope.App.OFS.Services.ServiceManager.ServiceManager \
+     import ServiceManager
 
 from Zope.App.OFS.Services.LocalEventService.LocalEventService \
      import LocalEventService
 
-from Zope.App.OFS.Services.ServiceManager.ServiceDirective \
-     import ServiceDirective
+from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
+     import ServiceConfiguration
 
-from Zope.App.Traversing import getPhysicalPathString
+from Zope.App.Traversing import getPhysicalPathString, traverse
+
+from Zope.ComponentArchitecture import getService, getServiceManager
+
+from Zope.Exceptions import NotFoundError
 
 from Zope.Event import subscribe, unsubscribe, listSubscriptions, publishEvent
 from Zope.Event.tests.subscriber import DummySubscriber, DummyFilter
@@ -44,6 +45,10 @@
 from Zope.Event.GlobalEventService import GlobalEventService
 from Zope.Event.IEvent import IEvent
 from Zope.Event.ISubscriptionAware import ISubscriptionAware
+from Zope.App.OFS.Services.ConfigurationInterfaces \
+     import Active, Unregistered, Registered
+
+from Zope.Proxy.ContextWrapper import ContextWrapper
 
 from EventSetup import EventSetup
 
@@ -79,9 +84,9 @@
 class EventServiceTests(EventSetup, TestCase):
     
     def _createNestedServices(self):
-        self.createEventService(self.folder1)
-        self.createEventService(self.folder1_1)
-        self.createEventService(self.folder1_1_1)
+        self.createEventService('folder1')
+        self.createEventService('folder1/folder1_1')
+        self.createEventService('folder1/folder1_1/folder1_1_1')
     
     def _createSubscribers(self):
         self.rootFolder.setObject("rootFolderSubscriber", DummySubscriber())
@@ -106,8 +111,11 @@
     def testListSubscriptions1(self):
         "a non-subscribed subscriber gets an empty array"
         self._createSubscribers()
-        self.assertEqual([], self.rootFolder.getServiceManager().getService(
-            "Events").listSubscriptions(self.rootFolderSubscriber))
+
+        events = getService(self.rootFolder, "Events")
+        
+        self.assertEqual(events.listSubscriptions(self.rootFolderSubscriber),
+                         [])
     
     def testListSubscriptions2(self):
         "one subscription"
@@ -383,19 +391,23 @@
     def _createAlternateService(self, service):
         self._createSubscribers()
         self.folder2.setObject("folder2Subscriber", DummySubscriber())
-        self.folder2Subscriber=ContextWrapper(
+        self.folder2Subscriber = ContextWrapper(
             self.folder2["folder2Subscriber"],
             self.folder2,
             name="folder2Subscriber")
+        
         if not self.folder2.hasServiceManager():
-            self.createServiceManager(self.folder2)
-        sm=getServiceManager(self.folder2) # wrapped now
-        sm.Packages['default'].setObject("myEventService", service)
+            self.folder2.setServiceManager(ServiceManager())
+
+        sm = traverse(self.rootFolder, 'folder2/++etc++Services')
+        default = traverse(sm, 'Packages/default')
+
+        default.setObject("myEventService", service)
 
         path = "%s/Packages/default/myEventService" % getPhysicalPathString(sm)
-        directive = ServiceDirective("Events", path)
-        sm.Packages['default'].setObject("myEventServiceDir", directive)
-        sm.bindService(directive)
+        configuration = ServiceConfiguration("Events", path)
+        default['configure'].setObject("myEventServiceDir", configuration)
+        traverse(default, 'configure/1').status = Active
 
         subscribe(
             self.rootFolderSubscriber,
@@ -439,9 +451,11 @@
             self.folder1_1Subscriber,
             event_type=IObjectAddedEvent
             )
-        sm=getServiceManager(self.folder1)
-        directive = sm.getDirectives("Events")[0]
-        sm.unbindService(directive)
+
+        sm = traverse(self.rootFolder, "folder1/++etc++Services")
+        configuration = sm.queryConfigurations("Events").active()
+        configuration.status = Registered
+
         publishEvent(self.rootFolder, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.folder1Subscriber.notified, 0)
         self.assertEqual(self.folder1_1Subscriber.notified, 1)
@@ -455,9 +469,11 @@
         publishEvent(self.rootFolder, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.folder2Subscriber.notified, 0)
         self.assertEqual(self.rootFolderSubscriber.notified, 1)
-        sm=getServiceManager(self.folder2)
-        directive = sm.getDirectives("Events")[0]
-        sm.unbindService(directive) # make sure it doesn't raise any errors
+
+        sm = traverse(self.rootFolder, "folder2/++etc++Services")
+        configuration = sm.queryConfigurations("Events").active()
+        # make sure it doesn't raise any errors
+        configuration.status = Registered
         
     def testSubscriptionAwareInteraction(self):
         sub = DummySubscriptionAwareSubscriber()