Commit 85654d87 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[test] create_data_object now support being given an archive unit

Well, technically an archive unit sequence.
parent 73eeef6adc7e
...@@ -73,10 +73,7 @@ class ContainerTC(CubicWebTC): ...@@ -73,10 +73,7 @@ class ContainerTC(CubicWebTC):
"""Functional test for SEDA component clone.""" """Functional test for SEDA component clone."""
with self.admin_access.repo_cnx() as cnx: with self.admin_access.repo_cnx() as cnx:
unit, unit_alt, unit_alt_seq = create_archive_unit(None, cnx=cnx) unit, unit_alt, unit_alt_seq = create_archive_unit(None, cnx=cnx)
bdo = create_data_object(None, cnx=cnx) bdo = create_data_object(unit_alt_seq)
cnx.create_entity('SEDADataObjectReference', user_cardinality=u'0..n',
seda_data_object_reference=unit_alt_seq,
seda_data_object_reference_id=bdo)
cnx.commit() cnx.commit()
unit.cw_clear_all_caches() unit.cw_clear_all_caches()
......
...@@ -411,10 +411,7 @@ class CloneImportTC(CubicWebTC): ...@@ -411,10 +411,7 @@ class CloneImportTC(CubicWebTC):
unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx, unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx,
user_cardinality=u'1', user_cardinality=u'1',
user_annotation=u'plop') user_annotation=u'plop')
bdo = testutils.create_data_object(None, cnx=cnx, filename=u'file.txt') bdo = testutils.create_data_object(unit_alt_seq, filename=u'file.txt')
cnx.create_entity('SEDADataObjectReference', user_cardinality=u'0..n',
seda_data_object_reference=unit_alt_seq,
seda_data_object_reference_id=bdo)
self.transfer_eid = transfer.eid self.transfer_eid = transfer.eid
self.unit_eid = unit.eid self.unit_eid = unit.eid
self.bdo_eid = bdo.eid self.bdo_eid = bdo.eid
......
...@@ -39,14 +39,20 @@ def create_archive_unit(parent, **kwargs): ...@@ -39,14 +39,20 @@ def create_archive_unit(parent, **kwargs):
return au, alt, alt_seq return au, alt, alt_seq
def create_data_object(transfer, **kwargs): def create_data_object(parent, **kwargs):
cnx = kwargs.pop('cnx', getattr(transfer, '_cw', None)) cnx = getattr(parent, '_cw', None)
create = cnx.create_entity
kwargs.setdefault('id', u'bdo1') kwargs.setdefault('id', u'bdo1')
bdo = create('SEDABinaryDataObject', seda_binary_data_object=transfer, **kwargs) if parent.cw_etype == 'SEDAArchiveTransfer':
choice = create('SEDAAltBinaryDataObjectAttachment', kwargs['seda_binary_data_object'] = parent
reverse_seda_alt_binary_data_object_attachment=bdo) bdo = cnx.create_entity('SEDABinaryDataObject', **kwargs)
create('SEDAAttachment', seda_attachment=choice) # Choice cannot be empty choice = cnx.create_entity('SEDAAltBinaryDataObjectAttachment',
reverse_seda_alt_binary_data_object_attachment=bdo)
cnx.create_entity('SEDAAttachment', seda_attachment=choice) # Choice cannot be empty
if parent.cw_etype != 'SEDAArchiveTransfer':
cnx.create_entity('SEDADataObjectReference', user_cardinality=u'0..n',
seda_data_object_reference=parent,
seda_data_object_reference_id=bdo)
return bdo return bdo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment