[Testbot] Plone 4.3 - Python 2.7 - Build # 2052 - Still failing! - 7 failure(s)

jenkins at plone.org jenkins at plone.org
Mon Mar 17 00:13:00 UTC 2014


-------------------------------------------------------------------------------
Plone 4.3 - Python 2.7 - Build # 2052 - Still Failing!
-------------------------------------------------------------------------------

http://jenkins.plone.org/job/plone-4.3-python-2.7/2052/


-------------------------------------------------------------------------------
CHANGES
-------------------------------------------------------------------------------

Repository: plone.dexterity
Branch: refs/heads/master
Date: 2014-03-16T16:27:39-07:00
Author: David Glick (davisagli) <david at glicksoftware.com>
Commit: https://github.com/plone/plone.dexterity/commit/1ac2d02bdf58c264cc4b21664ecccfd1e7d69af6

preserve existing id when adding an item to a container

Files changed:
M CHANGES.rst
M plone/dexterity/tests/test_utils.py
M plone/dexterity/tests/test_views.py
M plone/dexterity/utils.py

diff --git a/CHANGES.rst b/CHANGES.rst
index fe63a17..3c6008e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,8 @@ Changelog
 2.2.2 (unreleased)
 ------------------
 
+- If an object being added to a container already has an id, preserve it.
+  [davisagli]
 
 2.2.1 (2014-02-14)
 ------------------
diff --git a/plone/dexterity/tests/test_utils.py b/plone/dexterity/tests/test_utils.py
index 3c6be7d..8ee228c 100644
--- a/plone/dexterity/tests/test_utils.py
+++ b/plone/dexterity/tests/test_utils.py
@@ -84,6 +84,37 @@ class IBehaviorSchema(Interface):
         schemata = schematas[0]
         self.assertTrue(schemata is IBehaviorSchema)
 
+    def testAddContentToContainer_preserves_existing_id(self):
+        from plone.dexterity.content import Item
+        from plone.dexterity.content import Container
+        container = Container()
+        container._ordering = u'unordered'
+
+        from zope.component import provideAdapter, provideUtility
+        from zope.container.interfaces import INameChooser
+        from zope.interface import Interface
+        from plone.app.content.namechooser import NormalizingNameChooser
+        from plone.folder.interfaces import IOrdering
+        from plone.folder.unordered import UnorderedOrdering
+        from plone.i18n.normalizer.interfaces import IURLNormalizer
+        from plone.i18n.normalizer import URLNormalizer
+        provideAdapter(NormalizingNameChooser, [Interface], INameChooser)
+        provideUtility(URLNormalizer(), IURLNormalizer)
+        provideAdapter(UnorderedOrdering, [Interface], IOrdering)
+
+        # if the item has an id already, use it
+        from plone.dexterity.utils import addContentToContainer
+        item = Item()
+        item.id = 'foo'
+        item = addContentToContainer(container, item, checkConstraints=False)
+        self.assertEqual(item.id, 'foo')
+
+        # unless it's a duplicate
+        item = Item()
+        item.id = 'foo'
+        item = addContentToContainer(container, item, checkConstraints=False)
+        self.assertEqual(item.id, 'foo-1')
+
 
 def test_suite():
     return unittest.defaultTestLoader.loadTestsFromName(__name__)
diff --git a/plone/dexterity/tests/test_views.py b/plone/dexterity/tests/test_views.py
index 5f8d5dc..864be3f 100644
--- a/plone/dexterity/tests/test_views.py
+++ b/plone/dexterity/tests/test_views.py
@@ -130,6 +130,7 @@ def test_add(self):
         obj.id = u"newid"
 
         self.expect(obj.id).result(u"newid")
+        self.expect(obj.id).result(u"newid")
         self.expect(obj.portal_type).result("testtype").count(0,None)
 
         # New object's FTI
diff --git a/plone/dexterity/utils.py b/plone/dexterity/utils.py
index 8ed1393..c83e1f5 100644
--- a/plone/dexterity/utils.py
+++ b/plone/dexterity/utils.py
@@ -173,7 +173,8 @@ def addContentToContainer(container, object, checkConstraints=True):
         if container_fti is not None and not container_fti.allowType(object.portal_type):
             raise ValueError("Disallowed subobject type: %s" % object.portal_type)
 
-    name = INameChooser(container).chooseName(None, object)
+    name = getattr(aq_base(object), 'id', None)
+    name = INameChooser(container).chooseName(name, object)
     object.id = name
 
     newName = container._setObject(name, object)




-------------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CHANGES.log
Type: application/octet-stream
Size: 3733 bytes
Desc: not available
URL: <http://lists.plone.org/pipermail/plone-testbot/attachments/20140317/509dd820/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: build.log
Type: application/octet-stream
Size: 87803 bytes
Desc: not available
URL: <http://lists.plone.org/pipermail/plone-testbot/attachments/20140317/509dd820/attachment-0003.obj>


More information about the Testbot mailing list