[Checkins] SVN: GenericSetup/trunk/ - Extend the ZCatalog
import/export mechanism to allow removal of
Jens Vagelpohl
jens at dataflake.org
Wed Jun 6 07:28:46 EDT 2007
Log message for revision 76398:
- Extend the ZCatalog import/export mechanism to allow removal of
metadata columns in addition to adding them.
(http://www.zope.org/Collectors/CMF/483)
Changed:
U GenericSetup/trunk/CHANGES.txt
U GenericSetup/trunk/ZCatalog/exportimport.py
U GenericSetup/trunk/ZCatalog/tests/test_exportimport.py
-=-
Modified: GenericSetup/trunk/CHANGES.txt
===================================================================
--- GenericSetup/trunk/CHANGES.txt 2007-06-06 10:56:08 UTC (rev 76397)
+++ GenericSetup/trunk/CHANGES.txt 2007-06-06 11:28:46 UTC (rev 76398)
@@ -2,6 +2,10 @@
GenericSetup 1.3-beta (unreleased)
+ - Extend the ZCatalog import/export mechanism to allow removal of
+ metadata columns in addition to adding them.
+ (http://www.zope.org/Collectors/CMF/483)
+
- Made sure we register Acquisition free objects as utilities in the
components handler.
Modified: GenericSetup/trunk/ZCatalog/exportimport.py
===================================================================
--- GenericSetup/trunk/ZCatalog/exportimport.py 2007-06-06 10:56:08 UTC (rev 76397)
+++ GenericSetup/trunk/ZCatalog/exportimport.py 2007-06-06 11:28:46 UTC (rev 76398)
@@ -139,5 +139,11 @@
if child.nodeName != 'column':
continue
col = str(child.getAttribute('value'))
+ if child.hasAttribute('remove'):
+ # Remove the column if it is there
+ if col in self.context.schema()[:]:
+ self.context.delColumn(col)
+ continue
if col not in self.context.schema()[:]:
self.context.addColumn(col)
+
Modified: GenericSetup/trunk/ZCatalog/tests/test_exportimport.py
===================================================================
--- GenericSetup/trunk/ZCatalog/tests/test_exportimport.py 2007-06-06 10:56:08 UTC (rev 76397)
+++ GenericSetup/trunk/ZCatalog/tests/test_exportimport.py 2007-06-06 11:28:46 UTC (rev 76398)
@@ -62,7 +62,7 @@
<extra name="index_type" value="Okapi BM25 Rank"/>
<extra name="lexicon_id" value="foo_plexicon"/>
</index>
- <column value="eggs"/>
+%s <column value="eggs"/>
<column value="spam"/>
</object>
"""
@@ -78,17 +78,33 @@
<extra name="lexicon_id" value="foo_plexicon"/>
</index>
<index name="non_existing" remove="True"/>
+ <column value="non_existing" remove="True"/>
+ <column value="bacon" remove="True"/>
</object>
"""
+# START SITUATION
+#
+# The catalog starts out as the _CATALOG_BODY above with the following
+# xml snippets inserted.
+
+_VOCABULARY_XML = """\
+ <object name="foo_vocabulary" meta_type="Vocabulary" deprecated="True"/>
+"""
+
_TEXT_XML = """\
<index name="foo_text" meta_type="TextIndex" deprecated="True"/>
"""
-_VOCABULARY_XML = """\
- <object name="foo_vocabulary" meta_type="Vocabulary" deprecated="True"/>
+_COLUMN_XML = """\
+ <column value="bacon"/>
"""
+# END SITUATION
+#
+# The catalog ends as the _CATALOG_BODY above with the following
+# xml snippets and some empty strings inserted.
+
_ZCTEXT_XML = """\
<index name="foo_text" meta_type="ZCTextIndex">
<indexed_attr value="foo_text"/>
@@ -97,7 +113,6 @@
</index>
"""
-
class ZCatalogXMLAdapterTests(BodyAdapterTestCase):
layer = ExportImportZCMLLayer
@@ -153,28 +168,31 @@
self._populate(self._obj)
obj._setObject('foo_vocabulary', Vocabulary('foo_vocabulary'))
obj.addIndex('foo_text', 'TextIndex')
+ obj.addColumn('bacon')
def setUp(self):
from Products.ZCatalog.ZCatalog import ZCatalog
BodyAdapterTestCase.setUp(self)
self._obj = ZCatalog('foo_catalog')
- self._BODY = _CATALOG_BODY % ('', '')
+ self._BODY = _CATALOG_BODY % ('', '', '')
def test_body_get_special(self):
+ # Assert that the catalog starts out the way we expect it to.
self._populate_special(self._obj)
context = DummySetupEnviron()
adapted = getMultiAdapter((self._obj, context), IBody)
self.assertEqual(adapted.body,
- _CATALOG_BODY % (_VOCABULARY_XML, _TEXT_XML))
+ _CATALOG_BODY % (_VOCABULARY_XML, _TEXT_XML, _COLUMN_XML))
def test_body_set_update(self):
+ # Assert that the catalog ends up the way we expect it to.
self._populate_special(self._obj)
context = DummySetupEnviron()
context._should_purge = False
adapted = getMultiAdapter((self._obj, context), IBody)
adapted.body = _CATALOG_UPDATE_BODY
- self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML))
+ self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML, ''))
def test_suite():
More information about the Checkins
mailing list