[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/app/schemacontent/ Replaced the custom registration with subscribers that set or clear

Jim Fulton jim at zope.com
Tue Apr 18 19:55:29 EDT 2006


Log message for revision 67088:
  Replaced the custom registration with subscribers that set or clear
  the definition names.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/app/schemacontent/configure.zcml
  U   Zope3/branches/jim-adapter/src/zope/app/schemacontent/content.py
  U   Zope3/branches/jim-adapter/src/zope/app/schemacontent/tests/test_content.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/schemacontent/configure.zcml
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/schemacontent/configure.zcml	2006-04-18 23:55:26 UTC (rev 67087)
+++ Zope3/branches/jim-adapter/src/zope/app/schemacontent/configure.zcml	2006-04-18 23:55:28 UTC (rev 67088)
@@ -19,14 +19,6 @@
 
   </localUtility>
 
-  <class class=".content.ContentComponentDefinitionRegistration">
-    <require
-      permission="zope.ManageServices"
-      interface="zope.app.component.interfaces.IUtilityRegistration"
-      set_schema="zope.app.component.interfaces.IUtilityRegistration"
-      />
-  </class>
-
 <!-- Content Component Instance -->
 
   <class class=".content.ContentComponentInstance">
@@ -34,6 +26,9 @@
       interface="zope.annotation.interfaces.IAttributeAnnotatable" />
   </class>
 
+  <subscriber handler=".content.registeredContentComponent" />
+  <subscriber handler=".content.unregisteredContentComponent" />
+
   <include package=".browser" />
 
 </configure>

Modified: Zope3/branches/jim-adapter/src/zope/app/schemacontent/content.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/schemacontent/content.py	2006-04-18 23:55:26 UTC (rev 67087)
+++ Zope3/branches/jim-adapter/src/zope/app/schemacontent/content.py	2006-04-18 23:55:28 UTC (rev 67088)
@@ -15,10 +15,13 @@
 
 $Id$
 """
+
+from zope import component
+import zope.component.interfaces
+
 from persistent import Persistent
 from persistent.dict import PersistentDict
 from zope.app.container.contained import Contained
-from zope.app.component.site import UtilityRegistration
 from zope.interface import directlyProvides, implements
 from zope.schema import getFields
 from zope.security.checker import CheckerPublic, Checker, defineChecker
@@ -26,7 +29,21 @@
 from interfaces import IContentComponentDefinition
 from interfaces import IContentComponentInstance
 
+ at component.adapter(
+    IContentComponentDefinition,
+    zope.component.interfaces.IRegistered,
+    )
+def registeredContentComponent(component, event):
+    component.name = event.object.name
 
+ at component.adapter(
+    IContentComponentDefinition,
+    zope.component.interfaces.IUnregistered,
+    )
+def unregisteredContentComponent(component, event):
+    component.name = None
+
+
 class ContentComponentDefinition(Persistent, Contained):
 
     implements(IContentComponentDefinition)
@@ -38,16 +55,6 @@
         self.permissions = PersistentDict()
 
 
-class ContentComponentDefinitionRegistration(UtilityRegistration):
-    """Content Component Registration"""
-
-    def activated(self):
-        self.component.name = self.name
-
-    def deactivated(self):
-        self.component.name = None
-
-
 class ContentComponentInstance(Persistent):
 
     implements(IContentComponentInstance)

Modified: Zope3/branches/jim-adapter/src/zope/app/schemacontent/tests/test_content.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/schemacontent/tests/test_content.py	2006-04-18 23:55:26 UTC (rev 67087)
+++ Zope3/branches/jim-adapter/src/zope/app/schemacontent/tests/test_content.py	2006-04-18 23:55:28 UTC (rev 67088)
@@ -16,6 +16,8 @@
 $Id$
 """
 import unittest
+from zope.testing import doctest
+from zope.app.testing import placelesssetup
 
 from zope.component.interfaces import ComponentLookupError
 from zope.interface import Interface, classImplements
@@ -25,9 +27,10 @@
 from zope.app import zapi
 from zope.app.component.interfaces import ILocalUtility
 from zope.app.container.interfaces import IAdding
-from zope.app.schemacontent.content import \
-     ContentComponentDefinition, ContentComponentDefinitionRegistration, \
-     ContentComponentInstance
+from zope.app.schemacontent.content import ContentComponentDefinition
+from zope.app.schemacontent.content import ContentComponentInstance
+from zope.app.schemacontent.content import registeredContentComponent
+from zope.app.schemacontent.content import unregisteredContentComponent
 from zope.app.schemacontent.interfaces import IContentComponentDefinition
 from zope.app.testing import setup, ztapi
 
@@ -36,43 +39,6 @@
     title = TextLine(title=u"title", default=u'Title goes here.')
     description = Text(title=u"desription")
 
-
-class ContentComponentDefinitionRegistrationTests(unittest.TestCase):
-
-    __name__ = __parent__ = None
-    
-    def setUp(self):
-        setup.placefulSetUp()
-        self.rootFolder = setup.buildSampleFolderTree()
-
-        mgr = setup.createSiteManager(self.rootFolder)
-
-        # Setup Definition
-        classImplements(ContentComponentDefinition, ILocalUtility)
-        classImplements(ContentComponentDefinition, IAttributeAnnotatable)
-        default = zapi.traverse(mgr, 'default')
-        default['TestDoc'] = ContentComponentDefinition()
-
-        # Setup Definition Registration
-        path = "%s/default/%s" % (zapi.getPath(mgr), 'TestDoc')
-        reg = ContentComponentDefinitionRegistration(
-            'TestDoc', IContentComponentDefinition, default['TestDoc'])
-        key = default.registrationManager.addRegistration(reg)
-        self.reg = zapi.traverse(default.registrationManager, key)
-        
-    def tearDown(self):
-        setup.placefulTearDown()
-
-    def test_activated(self):
-        self.reg.activated()
-        self.assertEqual(self.reg.component.name, 'TestDoc')
-
-    def test_deactivated(self):
-        self.test_activated()
-        self.reg.deactivated()
-        self.assertEqual(self.reg.component.name, None)
-
-
 class ContentComponentInstanceTests(unittest.TestCase):
     
     def test_getattr(self):
@@ -97,10 +63,39 @@
         self.assertEqual(doc.getSchema().__class__, IDocument.__class__)
         self.assertEqual(doc.getSchema().__dict__, IDocument.__dict__)
 
+def test_subscribers():
+    """
+There seems to be a desire for ContentComponentDefinitions to know the
+name they are registered under. The registeredContentComponent and
+unregisteredContentComponent subscribers set or clear a definition's
+name when the definition is registered or unregistered.
+
+    >>> import zope.component.interfaces
+    >>> class FauxRegistration:
+    ...     name = u'bob'
+    >>> definition = ContentComponentDefinition()
+    >>> registeredContentComponent(
+    ...     definition,
+    ...     zope.component.interfaces.Registered(FauxRegistration)
+    ...     )
+    >>> definition.name
+    u'bob'
+    >>> unregisteredContentComponent(
+    ...     definition,
+    ...     zope.component.interfaces.Unregistered(FauxRegistration)
+    ...     )
+    >>> print definition.name
+    None
+    
+"""
+
 def test_suite():
     return unittest.TestSuite((
-        unittest.makeSuite(ContentComponentDefinitionRegistrationTests),
         unittest.makeSuite(ContentComponentInstanceTests),
+        doctest.DocTestSuite(
+            setUp=placelesssetup.setUp,
+            tearDown=placelesssetup.tearDown,
+            ),
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list