[entities] Backport cloning feature for archive transfer
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 01 Mar 2017 12:17:33 +0100
changeset 2446 68d41b878667
parent 2445 2577d5c14718
child 2447 98f67b3a4b5c
[entities] Backport cloning feature for archive transfer
cubicweb_seda/entities/__init__.py
cubicweb_seda/i18n/en.po
cubicweb_seda/i18n/fr.po
cubicweb_seda/migration/0.8.0_Any.py
cubicweb_seda/schema/__init__.py
test/test_entities.py
--- a/cubicweb_seda/entities/__init__.py	Wed Mar 01 08:01:04 2017 +0100
+++ b/cubicweb_seda/entities/__init__.py	Wed Mar 01 12:17:33 2017 +0100
@@ -149,6 +149,13 @@
         return container and container[0] or None
 
 
+class SEDAArchiveTransferIClonableAdapter(IClonableAdapter):
+    """Cloning adapter for SEDA profiles."""
+    __select__ = is_instance('SEDAArchiveTransfer')
+    rtype = 'clone_of'
+    skiprtypes = ()
+
+
 class SEDAArchiveUnitIClonableAdapter(IClonableAdapter):
     """Cloning adapter for SEDA components."""
     __select__ = is_instance('SEDAArchiveUnit')
@@ -182,7 +189,7 @@
 
 
 def registration_callback(vreg):
-    vreg.register(SEDAArchiveUnitIClonableAdapter)
+    vreg.register_all(globals().values(), __name__)
     vreg.register(IContainer.build_class('SEDAArchiveTransfer'))
     vreg.register(IContainer.build_class('SEDAArchiveUnit'))  # archive unit may also be a container
     for etype, parent_relations in sorted(seda_profile_container_def(vreg.schema)):
--- a/cubicweb_seda/i18n/en.po	Wed Mar 01 08:01:04 2017 +0100
+++ b/cubicweb_seda/i18n/en.po	Wed Mar 01 12:17:33 2017 +0100
@@ -3920,6 +3920,10 @@
 msgid "clone_of"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of"
 msgstr ""
@@ -3927,6 +3931,10 @@
 msgid "clone_of_object"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of_object"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of_object"
 msgstr ""
--- a/cubicweb_seda/i18n/fr.po	Wed Mar 01 08:01:04 2017 +0100
+++ b/cubicweb_seda/i18n/fr.po	Wed Mar 01 12:17:33 2017 +0100
@@ -3934,6 +3934,10 @@
 msgid "clone_of"
 msgstr "source"
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of"
 msgstr ""
@@ -3941,6 +3945,10 @@
 msgid "clone_of_object"
 msgstr "copies"
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of_object"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of_object"
 msgstr ""
--- a/cubicweb_seda/migration/0.8.0_Any.py	Wed Mar 01 08:01:04 2017 +0100
+++ b/cubicweb_seda/migration/0.8.0_Any.py	Wed Mar 01 12:17:33 2017 +0100
@@ -26,3 +26,4 @@
 import_seda_schemes(cnx, lcsv_files=lcsv_files)
 
 drop_relation_type('seda_reply_code_list_version')
+add_relation_definition('SEDAArchiveTransfer', 'clone_of', 'SEDAArchiveTransfer')
--- a/cubicweb_seda/schema/__init__.py	Wed Mar 01 08:01:04 2017 +0100
+++ b/cubicweb_seda/schema/__init__.py	Wed Mar 01 12:17:33 2017 +0100
@@ -90,7 +90,16 @@
     inlined = False
 
 
-class clone_of(RelationDefinition):
+class clone_of_archive_transfer(RelationDefinition):
+    name = 'clone_of'
+    subject = 'SEDAArchiveTransfer'
+    object = 'SEDAArchiveTransfer'
+    cardinality = '?*'
+    inlined = True
+
+
+class clone_of_archive_unit(RelationDefinition):
+    name = 'clone_of'
     subject = 'SEDAArchiveUnit'
     object = 'SEDAArchiveUnit'
     cardinality = '?*'
--- a/test/test_entities.py	Wed Mar 01 08:01:04 2017 +0100
+++ b/test/test_entities.py	Wed Mar 01 12:17:33 2017 +0100
@@ -114,6 +114,30 @@
             cloned_bdo.cw_clear_all_caches()
             self.assertEqual(cloned_bdo.seda_binary_data_object[0].eid, transfer.eid)
 
+    def test_archive_transfer_clone(self):
+        """Functional test for SEDA profile cloning."""
+        with self.admin_access.repo_cnx() as cnx:
+            scheme = cnx.create_entity('ConceptScheme', title=u'Algorithms')
+            concept = scheme.add_concept(u'md5')
+            transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
+            cnx.create_entity('SEDAMessageDigestAlgorithmCodeListVersion',
+                              seda_message_digest_algorithm_code_list_version_from=transfer,
+                              seda_message_digest_algorithm_code_list_version_to=scheme)
+            unit, unit_alt, unit_alt_seq = create_archive_unit(
+                transfer, cnx=cnx, title=u'hello')
+            create_data_object(transfer, seda_algorithm=concept)
+            cnx.commit()
+
+            clone = cnx.create_entity('SEDAArchiveTransfer', title=u'Clone', clone_of=transfer)
+            cnx.commit()
+
+            self.assertEqual((clone.reverse_seda_message_digest_algorithm_code_list_version_from[0].
+                             seda_message_digest_algorithm_code_list_version_to[0].eid),
+                             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)
+
 
 class FakeEntity(object):
     cw_etype = 'Whatever'