[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/registration/ When getting removed events for registrations, do nothing if the

Jim Fulton jim at zope.com
Tue Jun 1 06:56:43 EDT 2004


Log message for revision 25146:

When getting removed events for registrations, do nothing if the
event object is the enclosing site.

No longer need a remove-event subscriber for registration managers
that deletes registrations.  This was done to trigger remove events,
but that's no longer necessary since we now get remove events for the
registrations when the registration manager is deleted by virtue of
sublocation dispatch.




-=-
Modified: Zope3/trunk/src/zope/app/registration/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/registration/configure.zcml	2004-06-01 10:56:39 UTC (rev 25145)
+++ Zope3/trunk/src/zope/app/registration/configure.zcml	2004-06-01 10:56:42 UTC (rev 25146)
@@ -57,10 +57,4 @@
          zope.app.container.interfaces.IObjectAddedEvent"
     />
 
-  <subscriber
-    factory=".registration.RegistrationManagerRemoveSubscriber"
-    for=".interfaces.IRegistrationManager
-         zope.app.container.interfaces.IObjectRemovedEvent"
-    />
-
 </configure>

Modified: Zope3/trunk/src/zope/app/registration/registration.py
===================================================================
--- Zope3/trunk/src/zope/app/registration/registration.py	2004-06-01 10:56:39 UTC (rev 25145)
+++ Zope3/trunk/src/zope/app/registration/registration.py	2004-06-01 10:56:42 UTC (rev 25146)
@@ -30,6 +30,8 @@
 from zope.app.container.contained import Contained
 from zope.app.container.contained import setitem, contained, uncontained
 from zope.app.dependable.interfaces import IDependable, DependencyError
+from zope.app.component.localservice import getLocalServices
+from zope.app.location import inside
 from zope.app.module.interfaces import IModuleManager
 from zope.app.registration import interfaces
 
@@ -516,6 +518,14 @@
 
 def SimpleRegistrationRemoveSubscriber(registration, event):
     """Receive notification of remove event."""
+
+    services = getLocalServices(registration)
+    removed = event.object
+    if (services == removed) or inside(services, removed):
+        # we don't really care if the rigistration is active or
+        # registered, since the site is going away.
+        return
+
     objectstatus = registration.status
 
     if objectstatus == interfaces.ActiveStatus:
@@ -660,11 +670,6 @@
     def registrations(self):
         return [zapi.traverse(self.context, path)
                 for path in self.getPaths()]
-
-def RegistrationManagerRemoveSubscriber(registration_manager, event):
-    """Receive notification of remove event."""
-    for name in registration_manager:
-        del registration_manager[name]
             
 class RegistrationManager(Persistent, Contained):
     """Registration manager

Modified: Zope3/trunk/src/zope/app/registration/tests/test_registrationmanager.py
===================================================================
--- Zope3/trunk/src/zope/app/registration/tests/test_registrationmanager.py	2004-06-01 10:56:39 UTC (rev 25145)
+++ Zope3/trunk/src/zope/app/registration/tests/test_registrationmanager.py	2004-06-01 10:56:42 UTC (rev 25146)
@@ -18,8 +18,6 @@
 from doctest import DocTestSuite
 from zope.app.registration.interfaces import IRegistrationManager
 from zope.app.registration.registration import RegistrationManager
-from zope.app.registration.registration \
-     import RegistrationManagerRemoveSubscriber
 from zope.app.site.tests import placefulsetup
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.app.traversing.api import traverse
@@ -348,27 +346,7 @@
     def __iter__(self):
         for n in self.keys():
             yield n
-        
-class TestRegistrationManagerRemoveSubscriber:
-    def test_subscriber():
-        """
-        First create a dummy registration manager with some
-        initial data.
-        
-          >>> regmgr = DummyRM()
-          >>> regmgr['foo'] = 'bar'
 
-        Notify:
-
-          >>> RegistrationManagerRemoveSubscriber(regmgr, None)
-
-        Check the results.
-
-          >>> regmgr
-          {}
-        
-        """
-
 class RegisterableContainerTests(placefulsetup.PlacefulSetup):
 
     def test_getRegistrationManager(self):
@@ -400,7 +378,6 @@
     import sys
     return TestSuite((
         makeSuite(Test),
-        DocTestSuite(sys.modules[__name__]),
         ))
 
 if __name__=='__main__':

Modified: Zope3/trunk/src/zope/app/registration/tests/test_registrations.py
===================================================================
--- Zope3/trunk/src/zope/app/registration/tests/test_registrations.py	2004-06-01 10:56:39 UTC (rev 25145)
+++ Zope3/trunk/src/zope/app/registration/tests/test_registrations.py	2004-06-01 10:56:42 UTC (rev 25146)
@@ -30,6 +30,7 @@
 from zope.app.dependable.interfaces import IDependable
 from zope.app.traversing.api import traverse
 from zope.security.proxy import Proxy
+from zope.app.container.contained import Contained
 from zope.app.container.contained import ObjectRemovedEvent
 from zope.app.tests import ztapi
 from zope.app.registration.interfaces import IRegistration
@@ -39,11 +40,12 @@
     ComponentRegistrationRemoveSubscriber, \
     ComponentRegistrationAddSubscriber
 from zope.app.traversing.interfaces import IPhysicallyLocatable
+import zope.interface
 
 class ITestComponent(Interface):
     pass
 
-class ComponentStub:
+class ComponentStub(Contained):
 
     implements(IDependable)
 
@@ -79,17 +81,34 @@
     
 class TestSimpleRegistrationEvents(TestCase):
 
-    def test_RemoveSubscriber(self):
+    def test_RemoveSubscriber(self):    
         reg = DummyRegistration()
         reg.status = ActiveStatus
 
+        # we need to simulate an enclosing site manager:
+        from zope.app.container.contained import Contained
+        services = Contained()
+        from zope.app.site.interfaces import ISiteManager
+        zope.interface.directlyProvides(services, ISiteManager)
+        reg.__parent__ = services
+
+        # we need an event. Initially, we create an event simulating delete
+        # of the services.  In this case, nothing should change:
+        from zope.app.container.contained import ObjectRemovedEvent
+        event = ObjectRemovedEvent(services)
+        SimpleRegistrationRemoveSubscriber(reg, event)
+        self.assertEquals(reg.status, ActiveStatus)
+
+        # Now we'll "remove" the registration:
+        event = ObjectRemovedEvent(reg)
+
         # test that removal fails with Active status
         self.assertRaises(DependencyError,
-                          SimpleRegistrationRemoveSubscriber, reg, None)
+                          SimpleRegistrationRemoveSubscriber, reg, event)
 
         # test that removal succeeds with Registered status
         reg.status = RegisteredStatus
-        SimpleRegistrationRemoveSubscriber(reg, None)
+        SimpleRegistrationRemoveSubscriber(reg, event)
 
         self.assertEquals(reg.status, UnregisteredStatus)
         




More information about the Zope3-Checkins mailing list