tests: use bytes in workflow export/import tests (#36515)
This commit is contained in:
parent
2aed9c1bc4
commit
ba6e5cd5a1
|
@ -5,7 +5,7 @@ import sys
|
|||
import shutil
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.six import BytesIO
|
||||
from quixote import cleanup
|
||||
from wcs import publisher
|
||||
|
||||
|
@ -167,15 +167,15 @@ def test_status_actions_named_existing_role(pub):
|
|||
commentable.parent = st1
|
||||
|
||||
wf2 = assert_import_export_works(wf)
|
||||
assert '<item role_id="2">Test Role named existing role</item>' in ET.tostring(indent(wf.export_to_xml()))
|
||||
assert b'<item role_id="2">Test Role named existing role</item>' in ET.tostring(indent(wf.export_to_xml()))
|
||||
assert wf2.possible_status[0].items[0].by == ['2']
|
||||
|
||||
# check that it works even if the role_id is not set
|
||||
xml_export_orig = ET.tostring(export_to_indented_xml(wf))
|
||||
xml_export = xml_export_orig.replace(
|
||||
'<item role_id="2">Test Role named existing role</item>',
|
||||
'<item>Test Role named existing role</item>')
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(StringIO(xml_export)))
|
||||
b'<item role_id="2">Test Role named existing role</item>',
|
||||
b'<item>Test Role named existing role</item>')
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(BytesIO(xml_export)))
|
||||
assert wf3.possible_status[0].items[0].by == ['2']
|
||||
|
||||
|
||||
|
@ -204,30 +204,30 @@ def test_status_actions_named_missing_role(pub):
|
|||
|
||||
# check that role name has precedence over id
|
||||
xml_export_orig = ET.tostring(export_to_indented_xml(wf))
|
||||
assert '<item role_id="3">Test Role A</item>' in xml_export_orig
|
||||
xml_export = xml_export_orig.replace('<item role_id="3">Test Role A</item>',
|
||||
'<item role_id="4">Test Role A</item>')
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(StringIO(xml_export)))
|
||||
assert b'<item role_id="3">Test Role A</item>' in xml_export_orig
|
||||
xml_export = xml_export_orig.replace(b'<item role_id="3">Test Role A</item>',
|
||||
b'<item role_id="4">Test Role A</item>')
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(BytesIO(xml_export)))
|
||||
assert wf3.possible_status[0].items[0].by == ['3']
|
||||
|
||||
# check that it creates a new role if there's no match on id and name
|
||||
xml_export = xml_export_orig.replace('<item role_id="3">Test Role A</item>',
|
||||
'<item role_id="999">foobar</item>')
|
||||
xml_export = xml_export_orig.replace(b'<item role_id="3">Test Role A</item>',
|
||||
b'<item role_id="999">foobar</item>')
|
||||
nb_roles = Role.count()
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(StringIO(xml_export)))
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(BytesIO(xml_export)))
|
||||
assert Role.count() == nb_roles+1
|
||||
|
||||
# check that it doesn't fallback on the id if there's no match on the
|
||||
# name
|
||||
nb_roles = Role.count()
|
||||
xml_export = xml_export_orig.replace('<item role_id="3">Test Role A</item>',
|
||||
'<item role_id="3">Test Role C</item>')
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(StringIO(xml_export)))
|
||||
xml_export = xml_export_orig.replace(b'<item role_id="3">Test Role A</item>',
|
||||
b'<item role_id="3">Test Role C</item>')
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(BytesIO(xml_export)))
|
||||
assert wf3.possible_status[0].items[0].by != ['3']
|
||||
assert Role.count() == nb_roles+1
|
||||
|
||||
# on the other hand, check that it uses the id when included_id is True
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(StringIO(xml_export)),
|
||||
wf3 = Workflow.import_from_xml_tree(ET.parse(BytesIO(xml_export)),
|
||||
include_id=True)
|
||||
assert wf3.possible_status[0].items[0].by == ['3']
|
||||
|
||||
|
@ -263,8 +263,8 @@ def test_export_to_model_action(pub):
|
|||
export_to = ExportToModel()
|
||||
export_to.label = 'test'
|
||||
upload = Upload('/foo/bar', content_type='application/vnd.oasis.opendocument.text')
|
||||
file_content = '''PK\x03\x04\x14\x00\x00\x08\x00\x00\'l\x8eG^\xc62\x0c\'\x00'''
|
||||
upload.fp = StringIO()
|
||||
file_content = b'''PK\x03\x04\x14\x00\x00\x08\x00\x00\'l\x8eG^\xc62\x0c\'\x00'''
|
||||
upload.fp = BytesIO()
|
||||
upload.fp.write(file_content)
|
||||
upload.fp.seek(0)
|
||||
export_to.model_file = UploadedFile(pub.APP_DIR, None, upload)
|
||||
|
@ -280,8 +280,8 @@ def test_export_to_model_action(pub):
|
|||
export_to = ExportToModel()
|
||||
export_to.label = 'test'
|
||||
upload = Upload('/foo/bar', content_type='text/rtf')
|
||||
file_content = ''
|
||||
upload.fp = StringIO()
|
||||
file_content = b''
|
||||
upload.fp = BytesIO()
|
||||
upload.fp.write(file_content)
|
||||
upload.fp.seek(0)
|
||||
export_to.model_file = UploadedFile(pub.APP_DIR, None, upload)
|
||||
|
@ -364,10 +364,10 @@ def test_commentable_action(pub):
|
|||
|
||||
# import legacy comment without required attribute
|
||||
xml_export = ET.tostring(export_to_indented_xml(wf))
|
||||
assert '<required>True</required>' in xml_export
|
||||
xml_export = xml_export.replace('<required>True</required>', '')
|
||||
assert '<required>True</required>' not in xml_export
|
||||
wf2 = Workflow.import_from_xml_tree(ET.parse(StringIO(xml_export)))
|
||||
assert b'<required>True</required>' in xml_export
|
||||
xml_export = xml_export.replace(b'<required>True</required>', b'')
|
||||
assert b'<required>True</required>' not in xml_export
|
||||
wf2 = Workflow.import_from_xml_tree(ET.parse(BytesIO(xml_export)))
|
||||
assert wf2.possible_status[0].items[0].required is False
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue