[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ - Component registry import: Add the ability to unregister a component
Jens Vagelpohl
jens at dataflake.org
Thu Sep 25 17:41:13 EDT 2008
Log message for revision 91491:
- Component registry import: Add the ability to unregister a component
by specifying the "remove" attribute inside a utility node.
(https://bugs.launchpad.net/zope-cmf/+bug/161728)
Changed:
U Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/trunk/Products/GenericSetup/components.py
U Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2008-09-25 21:35:16 UTC (rev 91490)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2008-09-25 21:41:11 UTC (rev 91491)
@@ -4,6 +4,10 @@
GenericSetup 1.5.0 (unreleased)
-------------------------------
+- Component registry import: Add the ability to unregister a component
+ by specifying the "remove" attribute inside a utility node.
+ (https://bugs.launchpad.net/zope-cmf/+bug/161728)
+
- Property import/export tests: Add testing for non-ASCII properties.
(https://bugs.launchpad.net/zope-cmf/+bug/202356)
(https://bugs.launchpad.net/zope-cmf/+bug/242588)
Modified: Products.GenericSetup/trunk/Products/GenericSetup/components.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/components.py 2008-09-25 21:35:16 UTC (rev 91490)
+++ Products.GenericSetup/trunk/Products/GenericSetup/components.py 2008-09-25 21:41:11 UTC (rev 91491)
@@ -173,6 +173,11 @@
factory = child.getAttribute('factory')
factory = factory and _resolveDottedName(factory) or None
+ if ( child.hasAttribute('remove') and
+ self.context.queryUtility(provided, name) is not None ):
+ self.context.unregisterUtility(provided=provided, name=name)
+ continue
+
if component and factory:
raise ValueError, "Can not specify both a factory and a " \
"component in a utility registration."
Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py 2008-09-25 21:35:16 UTC (rev 91490)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py 2008-09-25 21:41:11 UTC (rev 91491)
@@ -39,6 +39,7 @@
from Products.GenericSetup.testing import BodyAdapterTestCase
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.testing import ExportImportZCMLLayer
+from Products.GenericSetup.tests.common import DummyImportContext
try:
from five.localsitemanager.registry import PersistentComponents
@@ -134,7 +135,25 @@
</componentregistry>
"""
+_REMOVE_IMPORT = """\
+<?xml version="1.0"?>
+<componentregistry>
+ <utilities>
+ <utility factory="Products.GenericSetup.tests.test_components.DummyUtility"
+ interface="Products.GenericSetup.tests.test_components.IDummyInterface"
+ remove="True"/>
+ <utility name="dummy tool name"
+ interface="Products.GenericSetup.tests.test_components.IDummyInterface"
+ object="dummy_tool" remove="True"/>
+ <utility name="foo"
+ factory="Products.GenericSetup.tests.test_components.DummyUtility"
+ interface="Products.GenericSetup.tests.test_components.IDummyInterface2"
+ remove="True"/>
+ </utilities>
+</componentregistry>
+"""
+
class ComponentRegistryXMLAdapterTests(BodyAdapterTestCase, unittest.TestCase):
layer = ExportImportZCMLLayer
@@ -239,6 +258,30 @@
util = queryUtility(IDummyInterface)
self.failUnless(util is None)
+ def test_remove_utilities(self):
+ from Products.GenericSetup.components import importComponentRegistry
+
+ obj = self._obj
+ self._populate(obj)
+ self._verifyImport(obj)
+
+ context = DummyImportContext(obj, False)
+ context._files['componentregistry.xml'] = _REMOVE_IMPORT
+ importComponentRegistry(context)
+
+ util = queryUtility(IDummyInterface2, name=u'foo')
+ self.failUnless(util is None)
+
+ util = queryUtility(IDummyInterface)
+ self.failUnless(util is None)
+
+ util = queryUtility(IDummyInterface, name='dummy tool name')
+ self.failUnless(util is None)
+
+ # This one should still exist
+ util = queryUtility(IDummyInterface2, name='dummy tool name2')
+ self.failIf(util is None)
+
def setUp(self):
# Create and enable a local component registry
site = Folder()
More information about the Checkins
mailing list