[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ During object manager imports do not throw an error when trying to remove an object that was already removed.

Maurits van Rees m.van.rees at zestsoftware.nl
Tue Feb 26 10:20:45 EST 2008


Log message for revision 84270:
  During object manager imports do not throw an error when trying to remove an object that was already removed.

Changed:
  U   Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
  U   Products.GenericSetup/trunk/Products/GenericSetup/tests/test_utils.py
  U   Products.GenericSetup/trunk/Products/GenericSetup/utils.py

-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2008-02-26 13:48:52 UTC (rev 84269)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2008-02-26 15:20:45 UTC (rev 84270)
@@ -2,6 +2,9 @@
 
   GenericSetup 1.4.0 (unreleased)
 
+    - During object manager imports do not throw an error when
+      trying to remove an object that was already removed.
+
     - utils: Added MarkerInterfaceHelpers.
 
     - Added default values to the registerProfile ZCML directive.

Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_utils.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_utils.py	2008-02-26 13:48:52 UTC (rev 84269)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_utils.py	2008-02-26 15:20:45 UTC (rev 84270)
@@ -161,7 +161,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.
@@ -457,6 +470,49 @@
         self.assertEqual(doc.toprettyxml(' '), _NORMAL_MARKER_EXPORT)
 
 
+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):
@@ -497,6 +553,7 @@
         unittest.makeSuite(UtilsTests),
         unittest.makeSuite(PropertyManagerHelpersTests),
         unittest.makeSuite(MarkerInterfaceHelpersTests),
+        unittest.makeSuite(ObjectManagerHelpersTests),
         unittest.makeSuite(PrettyDocumentTests),
         ))
 

Modified: Products.GenericSetup/trunk/Products/GenericSetup/utils.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/utils.py	2008-02-26 13:48:52 UTC (rev 84269)
+++ Products.GenericSetup/trunk/Products/GenericSetup/utils.py	2008-02-26 15:20:45 UTC (rev 84270)
@@ -589,7 +589,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