workflows: save webservice call response as bytes (#36515)
This commit is contained in:
parent
6c89239f3d
commit
b1fa54eb33
|
@ -1970,7 +1970,7 @@ def test_webservice_call_store_in_backoffice_filefield(http_requests, pub):
|
|||
fbo1 = formdata.data['bo1']
|
||||
assert fbo1.base_filename == 'file-bo1.xml'
|
||||
assert fbo1.content_type == 'text/xml'
|
||||
assert fbo1.get_content().startswith('<?xml')
|
||||
assert fbo1.get_content().startswith(b'<?xml')
|
||||
# nothing else is stored
|
||||
assert formdata.workflow_data is None
|
||||
assert not formdata.evolution[-1].parts
|
||||
|
@ -1987,7 +1987,7 @@ def test_webservice_call_store_in_backoffice_filefield(http_requests, pub):
|
|||
fbo1 = formdata.data['bo1']
|
||||
assert fbo1.base_filename == 'xxx.xml'
|
||||
assert fbo1.content_type == 'text/xml'
|
||||
assert fbo1.get_content().startswith('<?xml')
|
||||
assert fbo1.get_content().startswith(b'<?xml')
|
||||
# varname => workflow_data and AttachmentEvolutionPart
|
||||
assert formdata.workflow_data.get('xxx_status') == 200
|
||||
assert formdata.workflow_data.get('xxx_content_type') == 'text/xml'
|
||||
|
@ -3576,7 +3576,7 @@ def test_set_backoffice_field_file(http_requests, two_pubs):
|
|||
|
||||
formdata = formdef.data_class().get(formdata.id)
|
||||
assert formdata.data['bo1'].base_filename == 'hello.txt'
|
||||
assert formdata.data['bo1'].get_content() == 'hello world'
|
||||
assert formdata.data['bo1'].get_content() == b'hello world'
|
||||
|
||||
item = SetBackofficeFieldsWorkflowStatusItem()
|
||||
item.parent = st1
|
||||
|
@ -3586,7 +3586,7 @@ def test_set_backoffice_field_file(http_requests, two_pubs):
|
|||
|
||||
formdata = formdef.data_class().get(formdata.id)
|
||||
assert formdata.data['bo1'].base_filename == 'hello.txt'
|
||||
assert formdata.data['bo1'].get_content() == 'HELLO WORLD'
|
||||
assert formdata.data['bo1'].get_content() == b'HELLO WORLD'
|
||||
|
||||
hello_world = formdata.data['bo1']
|
||||
# check wrong value, or None (no file)
|
||||
|
@ -3604,7 +3604,7 @@ def test_set_backoffice_field_file(http_requests, two_pubs):
|
|||
formdata = formdef.data_class().get(formdata.id)
|
||||
if value is not None: # wrong value : do nothing
|
||||
assert formdata.data['bo1'].base_filename == 'hello.txt'
|
||||
assert formdata.data['bo1'].get_content() == 'HELLO WORLD'
|
||||
assert formdata.data['bo1'].get_content() == b'HELLO WORLD'
|
||||
assert LoggedError.count() == 1
|
||||
logged_error = LoggedError.select()[0]
|
||||
assert logged_error.summary.startswith('Failed to convert')
|
||||
|
|
|
@ -24,7 +24,7 @@ import mimetypes
|
|||
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.six import BytesIO
|
||||
|
||||
from quixote.html import TemplateIO, htmltext
|
||||
|
||||
|
@ -391,7 +391,7 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
|
|||
filename, content_type = self.get_attachment_data(response)
|
||||
workflow_data['%s_content_type' % self.varname] = content_type
|
||||
workflow_data['%s_length' % self.varname] = len(data)
|
||||
fp_content = StringIO(data)
|
||||
fp_content = BytesIO(data)
|
||||
attachment = AttachmentEvolutionPart(filename, fp_content,
|
||||
content_type=content_type,
|
||||
varname=self.varname)
|
||||
|
|
Loading…
Reference in New Issue