[Checkins] SVN: Products.GenericSetup/trunk/ Forward-port avoiding clearing unmodified indexes from 1.6 branch.
Tres Seaver
cvs-admin at zope.org
Wed Jan 23 22:18:40 UTC 2013
Log message for revision 129097:
Forward-port avoiding clearing unmodified indexes from 1.6 branch.
Changed:
_U Products.GenericSetup/trunk/
U Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/exportimport.py
U Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/tests/test_exportimport.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/exportimport.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/exportimport.py 2013-01-23 22:18:39 UTC (rev 129096)
+++ Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/exportimport.py 2013-01-23 22:18:39 UTC (rev 129097)
@@ -54,8 +54,9 @@
if child.nodeName == 'indexed_attr':
indexed_attrs.append(
child.getAttribute('value').encode('utf-8'))
- self.context.indexed_attrs = indexed_attrs
- self.context.clear()
+ if self.context.indexed_attrs != indexed_attrs:
+ self.context.indexed_attrs = indexed_attrs
+ self.context.clear()
node = property(_exportNode, _importNode)
@@ -77,11 +78,18 @@
def _importNode(self, node):
"""Import the object from the DOM node.
"""
+ _before = {'map': self.context._properties,
+ 'items': self.context.propertyItems(),
+ }
if self.environ.shouldPurge():
self._purgeProperties()
self._initProperties(node)
- self.context.clear()
+ _after = {'map': self.context._properties,
+ 'items': self.context.propertyItems(),
+ }
+ if _before != _after:
+ self.context.clear()
node = property(_exportNode, _importNode)
@@ -104,9 +112,12 @@
def _importNode(self, node):
"""Import the object from the DOM node.
"""
+ _before = (self.context._since_field, self.context._until_field)
self.context._edit(node.getAttribute('since_field').encode('utf-8'),
node.getAttribute('until_field').encode('utf-8'))
- self.context.clear()
+ _after = (self.context._since_field, self.context._until_field)
+ if _before != _after:
+ self.context.clear()
node = property(_exportNode, _importNode)
@@ -143,9 +154,12 @@
def _importNode(self, node):
"""Import the object from the DOM node.
"""
+ _before = self.context.expr
self.context.setExpression(
node.getAttribute('expression').encode('utf-8'))
- self.context.clear()
+ _after = self.context.expr
+ if _before != _after:
+ self.context.clear()
node = property(_exportNode, _importNode)
@@ -178,6 +192,7 @@
set = self.context.filteredSets[set_id]
importer = queryMultiAdapter((set, self.environ), INode)
importer.node = child
- self.context.clear()
+ # Let the filtered sets handle themselves: we have no state
+ #self.context.clear()
node = property(_exportNode, _importNode)
Modified: Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/tests/test_exportimport.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/tests/test_exportimport.py 2013-01-23 22:18:39 UTC (rev 129096)
+++ Products.GenericSetup/trunk/Products/GenericSetup/PluginIndexes/tests/test_exportimport.py 2013-01-23 22:18:39 UTC (rev 129097)
@@ -182,6 +182,107 @@
self._XML = _TOPIC_XML
+class UnchangedTests(unittest.TestCase):
+
+ layer = ExportImportZCMLLayer
+
+ def test_FieldIndex(self):
+ from xml.dom.minidom import parseString
+ from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
+ from Products.GenericSetup.testing import DummySetupEnviron
+ from Products.GenericSetup.PluginIndexes.exportimport \
+ import PluggableIndexNodeAdapter
+ environ = DummySetupEnviron()
+ def _no_clear(*a):
+ raise AssertionError("Don't clear me!")
+ index = FieldIndex('foo_field')
+ index.indexed_attrs = ['bar']
+ index.clear = _no_clear
+ adapted = PluggableIndexNodeAdapter(index, environ)
+ adapted.node = parseString(_FIELD_XML).documentElement # no raise
+
+ def test_KeywordIndex(self):
+ from xml.dom.minidom import parseString
+ from Products.PluginIndexes.KeywordIndex.KeywordIndex \
+ import KeywordIndex
+ from Products.GenericSetup.testing import DummySetupEnviron
+ from Products.GenericSetup.PluginIndexes.exportimport \
+ import PluggableIndexNodeAdapter
+ environ = DummySetupEnviron()
+ def _no_clear(*a):
+ raise AssertionError("Don't clear me!")
+ index = KeywordIndex('foo_keyword')
+ index.indexed_attrs = ['bar']
+ index.clear = _no_clear
+ adapted = PluggableIndexNodeAdapter(index, environ)
+ adapted.node = parseString(_KEYWORD_XML).documentElement # no raise
+
+ def test_DateIndex(self):
+ from xml.dom.minidom import parseString
+ from Products.PluginIndexes.DateIndex.DateIndex import DateIndex
+ from Products.GenericSetup.testing import DummySetupEnviron
+ from Products.GenericSetup.PluginIndexes.exportimport \
+ import DateIndexNodeAdapter
+ environ = DummySetupEnviron()
+ def _no_clear(*a):
+ raise AssertionError("Don't clear me!")
+ index = DateIndex('foo_date')
+ index._setPropValue('index_naive_time_as_local', True)
+ index.clear = _no_clear
+ adapted = DateIndexNodeAdapter(index, environ)
+ adapted.node = parseString(_DATE_XML).documentElement # no raise
+
+ def test_DateRangeIndex(self):
+ from xml.dom.minidom import parseString
+ from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \
+ import DateRangeIndex
+ from Products.GenericSetup.testing import DummySetupEnviron
+ from Products.GenericSetup.PluginIndexes.exportimport \
+ import DateRangeIndexNodeAdapter
+ environ = DummySetupEnviron()
+ def _no_clear(*a):
+ raise AssertionError("Don't clear me!")
+ index = DateRangeIndex('foo_daterange')
+ index._since_field = 'bar'
+ index._until_field = 'baz'
+ index.clear = _no_clear
+ adapted = DateRangeIndexNodeAdapter(index, environ)
+ adapted.node = parseString(_DATERANGE_XML).documentElement # no raise
+
+ def test_FilteredSet(self):
+ from xml.dom.minidom import parseString
+ from Products.PluginIndexes.TopicIndex.FilteredSet \
+ import PythonFilteredSet
+ from Products.GenericSetup.testing import DummySetupEnviron
+ from Products.GenericSetup.PluginIndexes.exportimport \
+ import FilteredSetNodeAdapter
+ environ = DummySetupEnviron()
+ def _no_clear(*a):
+ raise AssertionError("Don't clear me!")
+ index = PythonFilteredSet('bar', 'True')
+ index.clear = _no_clear
+ adapted = FilteredSetNodeAdapter(index, environ)
+ adapted.node = parseString(_SET_XML).documentElement # no raise
+
+ def test_TopicIndex(self):
+ from xml.dom.minidom import parseString
+ from Products.PluginIndexes.TopicIndex.TopicIndex import TopicIndex
+ from Products.GenericSetup.testing import DummySetupEnviron
+ from Products.GenericSetup.PluginIndexes.exportimport \
+ import TopicIndexNodeAdapter
+ environ = DummySetupEnviron()
+ def _no_clear(*a):
+ raise AssertionError("Don't clear me!")
+ index = TopicIndex('topics')
+ index.addFilteredSet('bar', 'PythonFilteredSet', 'True')
+ index.addFilteredSet('baz', 'PythonFilteredSet', 'False')
+ bar = index.filteredSets['bar']
+ baz = index.filteredSets['baz']
+ bar.clear = baz.clear = _no_clear
+ adapted = TopicIndexNodeAdapter(index, environ)
+ adapted.node = parseString(_SET_XML).documentElement # no raise
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DateIndexNodeAdapterTests),
@@ -191,4 +292,5 @@
unittest.makeSuite(PathIndexNodeAdapterTests),
unittest.makeSuite(FilteredSetNodeAdapterTests),
unittest.makeSuite(TopicIndexNodeAdapterTests),
+ unittest.makeSuite(UnchangedTests),
))
More information about the checkins
mailing list