[PATCH 1 of 3 seda] [entities/clone] Ensure we don't clone twice

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Mar 7 18:51:32 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488908847 -3600
#      Tue Mar 07 18:47:27 2017 +0100
# Node ID e78b9882d3975adb629996b4849ff3e3b540de30
# Parent  d4c0e6edccf6541c102e8f3166b7b1bf88d70316
[entities/clone] Ensure we don't clone twice

by copying the clone_of relation.

diff --git a/cubicweb_seda/site_cubicweb.py b/cubicweb_seda/site_cubicweb.py
--- a/cubicweb_seda/site_cubicweb.py
+++ b/cubicweb_seda/site_cubicweb.py
@@ -48,10 +48,12 @@ def __init__(self, __module__=None):
     super(rtags.RelationTags, self).__init__()
     self._tagdefs = {}
 
 
 Entity.cw_skip_copy_for.append(('container', 'subject'))
+Entity.cw_skip_copy_for.append(('clone_of', 'subject'))
+Entity.cw_skip_copy_for.append(('clone_of', 'object'))
 
 
 # auto-configuration of custom fields ##############################################################
 # (https://www.cubicweb.org/ticket/14474840)
 # other part in views/patches
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -136,10 +136,31 @@ class ContainerTC(CubicWebTC):
                              scheme.eid)
             seq = clone.archive_units[0]. first_level_choice.content_sequence
             self.assertEqual(seq.title.title, 'hello')
             self.assertEqual(transfer.binary_data_objects[0].seda_algorithm[0].eid, concept.eid)
 
+    def test_container_clone_clone(self):
+        """Functional test for SEDA component clone."""
+        with self.admin_access.repo_cnx() as cnx:
+            unit, unit_alt, unit_alt_seq = create_archive_unit(None, cnx=cnx)
+            cnx.commit()
+
+            cloned = cnx.create_entity(unit.cw_etype, user_annotation=u'x', clone_of=unit)
+            cnx.commit()
+            cloned.cw_clear_all_caches()
+
+            cloned2 = cnx.create_entity(unit.cw_etype, user_annotation=u'Y')
+            # mimick what's occurs when you're using the copy form
+            cloned2.copy_relations(cloned.eid)  # 1. copy relation
+            self.assertFalse(cloned2.clone_of)
+            cloned2.cw_set(clone_of=cloned.eid)  # 2. execute __linkto (which trigger cloning)
+
+            cnx.commit()
+
+            cloned2.cw_clear_all_caches()
+            self.assertEqual(len(cloned2.seda_alt_archive_unit_archive_unit_ref_id), 1)
+
 
 class FakeEntity(object):
     cw_etype = 'Whatever'
 
     def __init__(self, _cw):


More information about the saem-devel mailing list