[PATCH 2 of 3 saem] [test] Extend new_version_of cloning test to ensure data_object_reference_id relation is properly handled

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Dec 13 09:31:53 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1513153537 -3600
#      Wed Dec 13 09:25:37 2017 +0100
# Node ID d29e9194daad16f4a916e93563815a5297dd4758
# Parent  73545aea619e9188873c67e562843c2de776cd93
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r d29e9194daad
[test] Extend new_version_of cloning test to ensure data_object_reference_id relation is properly handled

This is actually fixed in yet-unreleased seda cube, but since the clone adapter
for new_version_of is defined in there, ensure the fix also applies there by
extending the existing test for it.

diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,3 +1,4 @@
 mock
 pytest
 webtest
+http://hg.logilab.org/review/cubes/seda/archive/tip.tar.bz2#egg=cubicweb-seda
diff --git a/test/unittest_entities_container.py b/test/unittest_entities_container.py
--- a/test/unittest_entities_container.py
+++ b/test/unittest_entities_container.py
@@ -79,11 +79,13 @@ class TreeTC(CubicWebTC):
     def test_seda_profile_clone(self):
         """Functional test for SEDA profile cloning."""
         with self.admin_access.repo_cnx() as cnx:
             transfer = testutils.setup_profile(cnx)
             unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(transfer)
-            testutils.create_data_object(transfer)
+            # don't add link from data object to transfer intentionally to force
+            # going through the archive unit to clone it
+            bdo = testutils.create_data_object(unit_alt_seq)
             cnx.commit()
             transfer.cw_adapt_to('IWorkflowable').fire_transition('publish')
             testutils.organization_unit(cnx, u'bob', archival_roles=['deposit'],
                                         use_profile=transfer)
             cnx.commit()
@@ -99,9 +101,20 @@ class TreeTC(CubicWebTC):
             # have been copied (but other parts of the test live in the seda
             # cube)
             self.assertEqual(clone.ark_naa[0].eid, transfer.ark_naa[0].eid)
             self.assertEqual(len(clone.reverse_use_profile), 0)
 
+            # Ensure data object is cloned through data_object_reference_id and
+            # container relation is properly handled
+            bdo_clone = cnx.execute('Any MAX(X) WHERE X is SEDABinaryDataObject').one()
+            self.assertNotEqual(bdo_clone.eid, bdo.eid)
+            bdo.cw_clear_all_caches()
+            self.assertEqual([e.eid for e in bdo.container], [transfer.eid])
+            self.assertEqual([e.eid for e in bdo_clone.container], [clone.eid])
+
+            self.failIf(cnx.execute('Any X GROUPBY X WHERE X container C HAVING COUNT(C) > 1'))
+            self.failIf(cnx.execute('Any X WHERE NOT X container C'))
+
 
 if __name__ == '__main__':
     import unittest
     unittest.main()


More information about the saem-devel mailing list