[test] Introduce create_data_object utility function
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Aug 2016 17:30:51 +0200
changeset 1557 789ccdadf81d
parent 1556 347aa6ee8338
child 1558 a12c97e1c4d4
[test] Introduce create_data_object utility function
test/testutils.py
--- a/test/testutils.py	Fri Aug 26 08:14:16 2016 +0200
+++ b/test/testutils.py	Thu Aug 25 17:30:51 2016 +0200
@@ -20,10 +20,7 @@
     """Create minimal ArchiveTransfer down to a BinaryDataObject and return the later."""
     create = cnx.create_entity
     transfer = create('SEDAArchiveTransfer', title=u'test profile')
-    bdo = create('SEDABinaryDataObject', id=u"bdo1", seda_binary_data_object=transfer)
-    choice = create('SEDAAltBinaryDataObjectAttachment',
-                    reverse_seda_alt_binary_data_object_attachment=bdo)
-    create('SEDAAttachment', seda_attachment=choice)  # Choice cannot be empty
+    bdo = create_data_object(transfer)
     # commit and clear cache to allow access to container relation
     cnx.commit()
     bdo.cw_clear_all_caches()
@@ -42,6 +39,16 @@
     return au, alt, alt_seq
 
 
+def create_data_object(transfer, **kwargs):
+    create = transfer._cw.create_entity
+    kwargs.setdefault('id', u'bdo1')
+    bdo = create('SEDABinaryDataObject', seda_binary_data_object=transfer, **kwargs)
+    choice = create('SEDAAltBinaryDataObjectAttachment',
+                    reverse_seda_alt_binary_data_object_attachment=bdo)
+    create('SEDAAttachment', seda_attachment=choice)  # Choice cannot be empty
+    return bdo
+
+
 def map_cs_to_rtype(scheme, rtype):
     cnx = scheme._cw
     cnx.execute('SET CS scheme_relation_type RT WHERE CS eid %(cs)s, RT name %(rt)s',