[hooks] Keep cardinality of mime type / format id optional
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 03 Nov 2017 08:40:47 +0100
changeset 2843 3f80d9099b20
parent 2842 28ee5b4012ae
child 2844 f287617a85f7
[hooks] Keep cardinality of mime type / format id optional so those information may be skipped by the application generating the transfer (e.g. to let the SAE do what's necessary, or because the format isn't supported by SEDA 0.2 or 1). This follows discussion with coproj/adullact about needs and pratices in the archival community.
cubicweb_seda/hooks.py
test/test_hooks.py
--- a/cubicweb_seda/hooks.py	Fri Nov 03 08:31:05 2017 +0100
+++ b/cubicweb_seda/hooks.py	Fri Nov 03 08:40:47 2017 +0100
@@ -439,18 +439,10 @@
                 # don't afford doing this in components which are not bound to
                 # vocabularies, it will be done upon import in a transfer
                 continue
-            if not bdo.file_category:
-                # no related category
-                card = u'0..1'
-                eids = None
-            else:
-                card = u'1'
+            bdo.mime_type.cw_set(seda_mime_type_to=None)
+            bdo.format_id.cw_set(seda_format_id_to=None)
+            if bdo.file_category:
                 eids = ','.join(str(x.eid) for x in bdo.file_category)
-            bdo.mime_type.cw_set(user_cardinality=card,
-                                 seda_mime_type_to=None)
-            bdo.format_id.cw_set(user_cardinality=card,
-                                 seda_format_id_to=None)
-            if eids is not None:
                 self.cnx.execute(self.set_mime_type_rql.format(eids=eids),
                                  {'x': bdo.mime_type.eid, 'c': container.eid})
                 self.cnx.execute(self.set_format_id_rql.format(eids=eids),
--- a/test/test_hooks.py	Fri Nov 03 08:31:05 2017 +0100
+++ b/test/test_hooks.py	Fri Nov 03 08:40:47 2017 +0100
@@ -241,17 +241,17 @@
 
             bdo.cw_set(file_category=categories['document'])
             cnx.commit()
-            self.assertFormatEqual(bdo, u'1',
+            self.assertFormatEqual(bdo,
                                    [concepts['application/msword'], concepts['application/pdf']],
                                    [concepts['fmt/37'], concepts['fmt/38'], concepts['fmt/14']])
 
             bdo.cw_set(file_category=None)
             cnx.commit()
-            self.assertFormatEqual(bdo, u'0..1', [], [])
+            self.assertFormatEqual(bdo, [], [])
 
             bdo.cw_set(file_category=categories['doc'])
             cnx.commit()
-            self.assertFormatEqual(bdo, u'1',
+            self.assertFormatEqual(bdo,
                                    [concepts['application/msword']],
                                    [concepts['fmt/37'], concepts['fmt/38']])
 
@@ -263,7 +263,7 @@
 
             bdo_comp.cw_set(file_category=categories['document'])
             cnx.commit()
-            self.assertFormatEqual(bdo_comp, u'0..1',
+            self.assertFormatEqual(bdo_comp,
                                    [],
                                    [])
             # until it's imported into some parent
@@ -271,18 +271,16 @@
             cnx.commit()
             transfer.cw_clear_relation_cache('seda_binary_data_object', 'object')
             imported_bdo, = [x for x in transfer.binary_data_objects if x.eid != bdo.eid]
-            self.assertFormatEqual(imported_bdo, u'1',
+            self.assertFormatEqual(imported_bdo,
                                    [concepts['application/msword'], concepts['application/pdf']],
                                    [concepts['fmt/37'], concepts['fmt/38'], concepts['fmt/14']])
 
-    def assertFormatEqual(self, bdo, cardinality, mime_types, format_ids):
+    def assertFormatEqual(self, bdo, mime_types, format_ids):
         bdo.cw_clear_all_caches()
         bdo.reverse_seda_mime_type_from[0].cw_clear_all_caches()
         bdo.reverse_seda_format_id_from[0].cw_clear_all_caches()
-        self.assertEqual(bdo.reverse_seda_mime_type_from[0].user_cardinality, cardinality)
         self.assertEqual(set(x.eid for x in bdo.reverse_seda_mime_type_from[0].seda_mime_type_to),
                          set(mime_types))
-        self.assertEqual(bdo.reverse_seda_format_id_from[0].user_cardinality, cardinality)
         self.assertEqual(set(x.eid for x in bdo.reverse_seda_format_id_from[0].seda_format_id_to),
                          set(format_ids))