[Testbot] Plone 5.0 - Python 2.7 - Build # 3066 - Fixed! - 0 failure(s)

jenkins at plone.org jenkins at plone.org
Fri Aug 22 17:53:55 UTC 2014


-------------------------------------------------------------------------------
Plone 5.0 - Python 2.7 - Build # 3066 - Fixed!
-------------------------------------------------------------------------------

http://jenkins.plone.org/job/plone-5.0-python-2.7/3066/


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

Repository: plone.app.linkintegrity
Branch: refs/heads/master
Date: 2014-08-22T18:15:12+02:00
Author: Patrick Gerken (do3cc) <do3cc at patrick-gerken.de>
Commit: https://github.com/plone/plone.app.linkintegrity/commit/139b4abef8781d9c7944d7f3ae278ff6a1945827

Fix failing test, probably fix real live problems with renaming dx objects

the bulk of the test fix happened in plone.app.referenceablebehavior

Files changed:
M plone/app/linkintegrity/references.py
M plone/app/linkintegrity/tests/test_functional.py

diff --git a/plone/app/linkintegrity/references.py b/plone/app/linkintegrity/references.py
index e665d29..24c54a5 100644
--- a/plone/app/linkintegrity/references.py
+++ b/plone/app/linkintegrity/references.py
@@ -10,25 +10,47 @@
 #
 # you have been warned! :)
 
-from logging import getLogger
-from Products.CMFCore.utils import getToolByName
+from OFS.interfaces import IItem
 from Products.Archetypes.exceptions import ReferenceException
-from ZODB.POSException import ConflictError
-from Products.Archetypes import config
-from Products.Archetypes.interfaces import IReferenceable
 from Products.Archetypes.interfaces import IBaseObject
+from Products.CMFCore.utils import getToolByName
+from ZODB.POSException import ConflictError
+from logging import getLogger
 
 
 def updateReferences(obj, relationship, newrefs):
+
+    # This for sure looks ugly, but is necessary to maintian AT compatibility
+    # newrefs are wrapped objects, but getRefreences returns the real objects
+    # to generate a difference, we must do the difference with the objects
+    # the adapters wrapped. This is what real_newrefs is about
+    # next, when adding references, we have to provide the wrapped object
+    # again, so we create a mapping, newref_r_a_mapping to get the
+    # wrapped object.
+
+    real_newrefs = set()
+    newref_r_a_mapping = {}
+    for newref in newrefs:
+        # Checking for IItem is a hack to check wether this reference
+        # is an adapter or a real object. Real Objects from AT are IItem
+        if not IItem.providedBy(newref):
+            real_newrefs.add(newref.context)
+            newref_r_a_mapping[newref.context] = newref
+        else:
+            real_newrefs.add(newref)
+
     existing = set(obj.getReferences(relationship=relationship))
-    for ref in newrefs.difference(existing):   # add new references and...
+
+    for ref in real_newrefs.difference(existing):   # add new references and...
         try:
-            obj.addReference(ref, relationship=relationship)
-        except (ReferenceException,AttributeError):
+            obj.addReference(newref_r_a_mapping.get(ref, ref), 
+                             relationship=relationship)
+        except (ReferenceException, AttributeError):
             pass
-    for ref in existing.difference(newrefs):   # removed leftovers
+    for ref in existing.difference(real_newrefs):   # removed leftovers
         try:
-            obj.deleteReference(ref, relationship=relationship)
+            obj.deleteReference(newref_r_a_mapping.get(ref, ref),
+                                relationship=relationship)
         except ReferenceException:
             removeDanglingReference(obj, relationship)
 
diff --git a/plone/app/linkintegrity/tests/test_functional.py b/plone/app/linkintegrity/tests/test_functional.py
index f604db7..025c3f3 100644
--- a/plone/app/linkintegrity/tests/test_functional.py
+++ b/plone/app/linkintegrity/tests/test_functional.py
@@ -103,7 +103,6 @@ def test_unreferenced_removal(self):
         self.assertIn('Test Page 1 has been deleted', self.browser.contents)
         self.assertNotIn('doc1', self.portal.objectIds())
 
-    @unittest.skip('XXX: No idea why this fails on DX')
     def test_renaming_referenced_item(self):
         doc1 = self.portal.doc1
         doc2 = self.portal.doc2




-------------------------------------------------------------------------------


More information about the Testbot mailing list