[entities/clone] Ensure we don't clone twice
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Mar 2017 18:47:27 +0100
changeset 2465 3b5249ffe7a1
parent 2462 2ba5bead36d2
child 2466 26bd2acc7285
[entities/clone] Ensure we don't clone twice by copying the clone_of relation.
cubicweb_seda/site_cubicweb.py
test/test_entities.py
--- a/cubicweb_seda/site_cubicweb.py	Tue Mar 07 17:02:20 2017 +0100
+++ b/cubicweb_seda/site_cubicweb.py	Tue Mar 07 18:47:27 2017 +0100
@@ -50,6 +50,8 @@
 
 
 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 ##############################################################
--- a/test/test_entities.py	Tue Mar 07 17:02:20 2017 +0100
+++ b/test/test_entities.py	Tue Mar 07 18:47:27 2017 +0100
@@ -138,6 +138,27 @@
             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'