[Checkins]
SVN: Products.GenericSetup/branches/1.3/Products/GenericSetup/
Merge 84270 from trunk: During object manager imports do not
throw an
Maurits van Rees
m.van.rees at zestsoftware.nl
Tue Feb 26 10:27:33 EST 2008
Log message for revision 84271:
Merge 84270 from trunk: During object manager imports do not throw an
error when trying to remove an object that was already removed.
Changed:
U Products.GenericSetup/branches/1.3/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_utils.py
U Products.GenericSetup/branches/1.3/Products/GenericSetup/utils.py
-=-
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/CHANGES.txt 2008-02-26 15:20:45 UTC (rev 84270)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/CHANGES.txt 2008-02-26 15:27:32 UTC (rev 84271)
@@ -2,6 +2,9 @@
GenericSetup 1.3.4 (unreleased)
+ - During object manager imports do not throw an error when
+ trying to remove an object that was already removed.
+
- content: Add simple guard against import failures when
the ".objects" file contains empty lines.
(https://bugs.launchpad.net/zope-cmf/+bug/176328)
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_utils.py
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_utils.py 2008-02-26 15:20:45 UTC (rev 84270)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_utils.py 2008-02-26 15:27:32 UTC (rev 84271)
@@ -145,7 +145,20 @@
</dummy>
"""
+_ADD_IMPORT = """\
+<?xml version="1.0"?>
+<dummy>
+ <object name="history" meta_type="Folder"/>
+</dummy>
+"""
+_REMOVE_IMPORT = """\
+<?xml version="1.0"?>
+<dummy>
+ <object name="history" remove="True"/>
+</dummy>
+"""
+
def _testFunc( *args, **kw ):
""" This is a test.
@@ -383,6 +396,49 @@
self.assertEquals(obj.lines3, ('Gee', 'Foo', 'Bar'))
+class ObjectManagerHelpersTests(unittest.TestCase):
+
+ def _getTargetClass(self):
+ from Products.GenericSetup.utils import ObjectManagerHelpers
+
+ return ObjectManagerHelpers
+
+ def _makeOne(self, *args, **kw):
+ from Products.GenericSetup.utils import NodeAdapterBase
+
+ class Foo(self._getTargetClass(), NodeAdapterBase):
+
+ pass
+
+ return Foo(*args, **kw)
+
+ def setUp(self):
+ from OFS.ObjectManager import ObjectManager
+
+ obj = ObjectManager('obj')
+ self.helpers = self._makeOne(obj, DummySetupEnviron())
+
+ def test__initObjects(self):
+ obj = self.helpers.context
+ self.failIf('history' in obj.objectIds())
+
+ # Add object
+ node = parseString(_ADD_IMPORT).documentElement
+ self.helpers._initObjects(node)
+ self.failUnless('history' in obj.objectIds())
+
+ # Remove it again
+ node = parseString(_REMOVE_IMPORT).documentElement
+ self.helpers._initObjects(node)
+ self.failIf('history' in obj.objectIds())
+
+ # Removing it a second time should not throw an
+ # AttributeError.
+ node = parseString(_REMOVE_IMPORT).documentElement
+ self.helpers._initObjects(node)
+ self.failIf('history' in obj.objectIds())
+
+
class PrettyDocumentTests(unittest.TestCase):
def test_attr_quoting(self):
@@ -421,6 +477,7 @@
return unittest.TestSuite((
unittest.makeSuite(UtilsTests),
unittest.makeSuite(PropertyManagerHelpersTests),
+ unittest.makeSuite(ObjectManagerHelpersTests),
unittest.makeSuite(PrettyDocumentTests),
))
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/utils.py
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/utils.py 2008-02-26 15:20:45 UTC (rev 84270)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/utils.py 2008-02-26 15:27:32 UTC (rev 84271)
@@ -587,7 +587,8 @@
obj_id = str(child.getAttribute('name'))
if child.hasAttribute('remove'):
- parent._delObject(obj_id)
+ if obj_id in parent.objectIds():
+ parent._delObject(obj_id)
continue
if obj_id not in parent.objectIds():
More information about the Checkins
mailing list