tests: read/write uploads as binary (#36515)

This commit is contained in:
Frédéric Péters 2019-11-12 21:40:15 +01:00
parent 6d80317832
commit 56e9be1142
6 changed files with 77 additions and 78 deletions

View File

@ -982,7 +982,7 @@ def test_form_import(pub):
# import an invalid file
resp = app.get('/backoffice/forms/')
resp = resp.click(href='import')
resp.form['file'] = Upload('formdef.wcs', 'garbage')
resp.form['file'] = Upload('formdef.wcs', b'garbage')
resp = resp.form.submit()
assert 'Invalid File' in resp.text
@ -2337,7 +2337,7 @@ def test_workflows_export_import(pub):
resp = app.get('/backoffice/workflows/')
resp = resp.click('Import')
resp.form['file'] = Upload('xxx.wcs', 'garbage')
resp.form['file'] = Upload('xxx.wcs', b'garbage')
resp = resp.form.submit('submit')
assert 'Invalid File' in resp.text
assert Workflow.count() == 2
@ -4249,7 +4249,7 @@ def test_settings_export_import(pub, studio):
resp = resp.form.submit('cancel')
resp = app.get('/backoffice/settings/import')
resp.form['file'] = Upload('export.wcs', 'invalid content')
resp.form['file'] = Upload('export.wcs', b'invalid content')
resp = resp.form.submit('submit')
assert 'Error: Not a valid export file' in resp.text
@ -4547,7 +4547,7 @@ def test_settings_idp(pub):
resp2 = resp.click('Identity Providers')
resp2 = resp2.click('New')
idp_metadata_filename = os.path.join(os.path.dirname(__file__), 'idp_metadata.xml')
resp2.form['metadata'] = Upload('idp_metadata.xml', open(idp_metadata_filename).read())
resp2.form['metadata'] = Upload('idp_metadata.xml', open(idp_metadata_filename, 'rb').read())
resp2 = resp2.form.submit('submit')
resp = resp.click('Identity Providers')

View File

@ -1893,7 +1893,7 @@ def test_form_draft_with_file(pub):
assert '<h3>Tracking code</h3>' in resp.text
tracking_code = get_displayed_tracking_code(resp)
assert tracking_code is not None
resp.forms[0]['f0$file'] = Upload('test.txt', 'foobar', 'text/plain')
resp.forms[0]['f0$file'] = Upload('test.txt', b'foobar', 'text/plain')
resp = resp.forms[0].submit('submit')
tracking_code_2 = get_displayed_tracking_code(resp)
assert tracking_code == tracking_code_2
@ -1928,7 +1928,7 @@ def test_form_draft_with_file_direct_validation(pub):
resp = login(get_app(pub), username='foo', password='foo').get('/test/')
formdef.data_class().wipe()
tracking_code = get_displayed_tracking_code(resp)
resp.forms[0]['f0$file'] = Upload('test2.txt', 'foobar2', 'text/plain')
resp.forms[0]['f0$file'] = Upload('test2.txt', b'foobar2', 'text/plain')
resp = resp.forms[0].submit('submit')
resp = login(get_app(pub), username='foo', password='foo').get('/')
@ -2689,7 +2689,7 @@ def test_form_file_field_submit(pub):
formdef.store()
formdef.data_class().wipe()
upload = Upload('test.txt', 'foobar', 'text/plain')
upload = Upload('test.txt', b'foobar', 'text/plain')
resp = get_app(pub).get('/test/')
resp.forms[0]['f0$file'] = upload
@ -2711,7 +2711,7 @@ def test_form_file_field_image_submit(pub):
formdef.store()
formdef.data_class().wipe()
image_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
image_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
upload = Upload('test.jpg', image_content, 'image/jpeg')
app = get_app(pub)
@ -2741,7 +2741,7 @@ def test_form_file_field_image_submit(pub):
assert resp.content_type == 'image/png'
# check a fake image is not sent back
upload = Upload('test.jpg', '<script>evil javascript</script>', 'image/jpeg')
upload = Upload('test.jpg', b'<script>evil javascript</script>', 'image/jpeg')
app = get_app(pub)
resp = app.get('/test/')
resp.forms[0]['f0$file'] = upload
@ -2754,7 +2754,7 @@ def test_form_file_field_submit_wrong_mimetype(pub):
formdef.store()
formdef.data_class().wipe()
upload = Upload('test.txt', 'foobar', 'application/force-download')
upload = Upload('test.txt', b'foobar', 'application/force-download')
resp = get_app(pub).get('/test/')
resp.forms[0]['f0$file'] = upload
@ -2770,7 +2770,7 @@ def test_form_file_field_submit_wrong_mimetype(pub):
assert resp.content_type == 'text/plain'
assert resp.text == 'foobar'
upload = Upload('test.pdf', '%PDF-1.4 ...', 'application/force-download')
upload = Upload('test.pdf', b'%PDF-1.4 ...', 'application/force-download')
resp = get_app(pub).get('/test/')
resp.forms[0]['f0$file'] = upload
@ -2970,7 +2970,7 @@ def test_formdata_attachment_download(pub):
resp = resp.follow()
assert 'The form has been recorded' in resp.text
resp.forms[0]['attachment_attach'] = Upload('test.txt', 'foobar', 'text/plain')
resp.forms[0]['attachment_attach'] = Upload('test.txt', b'foobar', 'text/plain')
resp = resp.forms[0].submit('button_attach')
assert formdef.data_class().count() == 1
@ -3013,7 +3013,7 @@ def test_formdata_attachment_download_with_substitution_variable(pub):
resp = resp.follow()
assert 'The form has been recorded' in resp.text
resp.forms[0]['attachment_attach'] = Upload('test.txt', 'foobar', 'text/plain')
resp.forms[0]['attachment_attach'] = Upload('test.txt', b'foobar', 'text/plain')
resp = resp.forms[0].submit('button_attach')
assert formdef.data_class().count() == 1
@ -3078,7 +3078,7 @@ def test_formdata_attachment_download_to_backoffice_file_field(pub):
resp = resp.follow()
assert 'The form has been recorded' in resp.text
resp.forms[0]['attachment_attach'] = Upload('test.txt', 'foobar', 'text/plain')
resp.forms[0]['attachment_attach'] = Upload('test.txt', b'foobar', 'text/plain')
resp = resp.forms[0].submit('button_attach')
# backoffice file field is set
@ -3129,7 +3129,7 @@ def test_formdata_attachment_download_to_backoffice_file_field_only(pub):
resp = resp.follow()
assert 'The form has been recorded' in resp.text
resp.forms[0]['attachment_attach'] = Upload('test.txt', 'foobar', 'text/plain')
resp.forms[0]['attachment_attach'] = Upload('test.txt', b'foobar', 'text/plain')
resp = resp.forms[0].submit('button_attach')
# backoffice file field is set
@ -3153,8 +3153,8 @@ def test_formdata_generated_document_download(pub):
export_to.convert_to_pdf = False
export_to.label = 'create doc'
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = StringIO()
upload.fp.write('HELLO WORLD')
upload.fp = BytesIO()
upload.fp.write(b'HELLO WORLD')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
export_to.id = '_export_to'
@ -3201,8 +3201,8 @@ def test_formdata_generated_document_download(pub):
# change export model to now be a RTF file, do the action again on the same form and
# check that both the old .odt file and the new .rtf file are there and valid.
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = StringIO()
upload.fp.write('HELLO NEW WORLD')
upload.fp = BytesIO()
upload.fp.write(b'HELLO NEW WORLD')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
wf.store()
@ -3217,8 +3217,8 @@ def test_formdata_generated_document_download(pub):
# use substitution variables on rtf: only ezt format is accepted
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = StringIO()
upload.fp.write('HELLO {{DJANGO}} WORLD [form_name]')
upload.fp = BytesIO()
upload.fp.write(b'HELLO {{DJANGO}} WORLD [form_name]')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
wf.store()
@ -3243,9 +3243,9 @@ def test_formdata_generated_document_odt_download(pub, odt_template):
export_to.convert_to_pdf = False
export_to.label = 'create doc'
template_filename = os.path.join(os.path.dirname(__file__), odt_template)
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/' + odt_template, content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
@ -3275,7 +3275,7 @@ def test_formdata_generated_document_odt_download(pub, odt_template):
resp = resp.follow() # $form/$id/create_doc
resp = resp.follow() # $form/$id/create_doc/
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
assert_equal_zip(BytesIO(resp.body), f)
resp = login(get_app(pub), username='foo', password='foo').get(form_location)
@ -3302,13 +3302,13 @@ def test_formdata_generated_document_odt_download(pub, odt_template):
assert resp.location.endswith('/' + odt_template)
resp = resp.follow()
assert resp.content_type == 'application/octet-stream'
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
assert_equal_zip(BytesIO(resp.body), f)
# change file content, same name
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = StringIO()
upload.fp.write('HELLO NEW WORLD')
upload.fp = BytesIO()
upload.fp.write(b'HELLO NEW WORLD')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
wf.store()
@ -3318,7 +3318,7 @@ def test_formdata_generated_document_odt_download(pub, odt_template):
assert resp.location == form_location
resp = resp.follow() # back to form page
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
body = resp.click(odt_template, index=0).follow().body
assert_equal_zip(BytesIO(body), f)
assert resp.click('test.rtf', index=0).follow().body == 'HELLO NEW WORLD'
@ -3332,9 +3332,9 @@ def test_formdata_generated_document_odt_download_with_substitution_variable(pub
export_to.label = 'create doc'
export_to.varname = 'created_doc'
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
@ -3364,7 +3364,7 @@ def test_formdata_generated_document_odt_download_with_substitution_variable(pub
resp = resp.follow() # $form/$id/create_doc
resp = resp.follow() # $form/$id/create_doc/
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
assert_equal_zip(BytesIO(resp.body), f)
export_to.attach_to_history = True
@ -3379,13 +3379,13 @@ def test_formdata_generated_document_odt_download_with_substitution_variable(pub
assert resp.location.endswith('/template.odt')
response1 = resp = resp.follow()
assert resp.content_type == 'application/octet-stream'
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
assert_equal_zip(BytesIO(resp.body), f)
# change file content, same name
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = StringIO()
upload.fp.write('HELLO NEW WORLD')
upload.fp = BytesIO()
upload.fp.write(b'HELLO NEW WORLD')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
wf.store()
@ -3395,9 +3395,9 @@ def test_formdata_generated_document_odt_download_with_substitution_variable(pub
assert resp.location == form_location
resp = resp.follow() # back to form page
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
body = resp.click('template.odt', index=0).follow().body
assert_equal_zip(StringIO(body), f)
assert_equal_zip(BytesIO(body), f)
response2 = resp.click('test.rtf', index=0).follow()
assert response2.body == 'HELLO NEW WORLD'
# Test attachment substitution variables
@ -3450,9 +3450,9 @@ def test_formdata_generated_document_odt_to_pdf_download(pub):
export_to.label = 'create doc'
export_to.varname = 'created_doc'
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
@ -3517,9 +3517,9 @@ def test_formdata_generated_document_odt_to_pdf_download_push_to_portfolio(pub,
export_to.label = 'create doc'
export_to.varname = 'created_doc'
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
@ -3605,9 +3605,9 @@ def test_formdata_generated_document_non_interactive(pub):
export_to.convert_to_pdf = False
export_to.method = 'non-interactive'
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
@ -3645,7 +3645,7 @@ def test_formdata_generated_document_non_interactive(pub):
assert resp.location.endswith('/template.odt')
resp = resp.follow()
assert resp.content_type == 'application/octet-stream'
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
assert_equal_zip(BytesIO(resp.body), f)
assert formdef.data_class().count() == 1
@ -3665,9 +3665,9 @@ def test_formdata_generated_document_to_backoffice_field(pub):
export_to.convert_to_pdf = False
export_to.method = 'non-interactive'
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
@ -3710,7 +3710,7 @@ def test_formdata_generated_document_to_backoffice_field(pub):
assert resp.location.endswith('/template.odt')
resp = resp.follow()
assert resp.content_type == 'application/octet-stream'
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt')) as f:
with open(os.path.join(os.path.dirname(__file__), 'template-out.odt'), 'rb') as f:
assert_equal_zip(BytesIO(resp.body), f)
assert formdef.data_class().count() == 1
@ -3732,8 +3732,8 @@ def test_formdata_generated_document_in_private_history(pub):
export_to = ExportToModel()
export_to.label = 'create doc'
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = StringIO()
upload.fp.write('HELLO WORLD')
upload.fp = BytesIO()
upload.fp.write(b'HELLO WORLD')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
export_to.attach_to_history = True
@ -3833,7 +3833,7 @@ def test_formdata_form_file_download(pub):
assert 'The form has been recorded' in resp.text
assert 'qommon.fileupload.js' in resp.text
resp.forms[0]['f1$file'] = Upload('test.txt', 'foobar', 'text/plain')
resp.forms[0]['f1$file'] = Upload('test.txt', b'foobar', 'text/plain')
resp = resp.forms[0].submit('submit')
assert formdef.data_class().count() == 1

View File

@ -221,10 +221,10 @@ def test_internal_identifier_migration(pub):
formdef.fields = []
formdef.store()
obj = pickle.load(open(formdef.get_object_filename()))
obj = pickle.load(open(formdef.get_object_filename(), 'rb'))
del obj.internal_identifier
pickle.dump(obj, open(formdef.get_object_filename(), 'w'))
assert pickle.load(open(formdef.get_object_filename())).internal_identifier is None
pickle.dump(obj, open(formdef.get_object_filename(), 'wb'))
assert pickle.load(open(formdef.get_object_filename(), 'rb')).internal_identifier is None
assert FormDef.get(formdef.id, ignore_migration=True).internal_identifier is None
formdef = FormDef.get(formdef.id)

View File

@ -373,14 +373,14 @@ def test_deploy():
# update
cleanup()
pub_cfg = pickle.load(open(os.path.join(alt_tempdir, 'wcs.example.net', 'config.pck')))
pub_cfg = pickle.load(open(os.path.join(alt_tempdir, 'wcs.example.net', 'config.pck'), 'rb'))
assert pub_cfg['language'] == {'language': 'fr'}
del pub_cfg['language']
pickle.dump(pub_cfg,
open(os.path.join(alt_tempdir, 'wcs.example.net', 'config.pck'), 'w'))
open(os.path.join(alt_tempdir, 'wcs.example.net', 'config.pck'), 'wb'))
hobo_cmd.execute(base_options, sub_options,
['http://wcs.example.net/', os.path.join(alt_tempdir, 'hobo.json')])
pub_cfg = pickle.load(open(os.path.join(alt_tempdir, 'wcs.example.net', 'config.pck')))
pub_cfg = pickle.load(open(os.path.join(alt_tempdir, 'wcs.example.net', 'config.pck'), 'rb'))
assert pub_cfg['language'] == {'language': 'fr'}
def test_configure_postgresql():

View File

@ -34,10 +34,10 @@ def test_migrate():
Role.wipe()
role = Role(name='Hello world')
role.store()
obj = pickle.load(open(role.get_object_filename()))
obj = pickle.load(open(role.get_object_filename(), 'rb'))
del obj.slug
pickle.dump(obj, open(role.get_object_filename(), 'w'))
assert pickle.load(open(role.get_object_filename())).slug is None
pickle.dump(obj, open(role.get_object_filename(), 'wb'))
assert pickle.load(open(role.get_object_filename(), 'rb')).slug is None
assert Role.get(role.id).slug == 'hello-world'
def test_get_user_roles():

View File

@ -8,7 +8,7 @@ import zipfile
import mock
from django.utils.six import StringIO
from django.utils.six import BytesIO, StringIO
from django.utils.six.moves.urllib import parse as urlparse
from quixote import cleanup, get_response
@ -876,7 +876,7 @@ def test_register_comment_attachment(pub):
shutil.rmtree(os.path.join(get_publisher().app_dir, 'attachments'))
formdata.evolution[-1].parts = [AttachmentEvolutionPart('hello.txt',
fp=StringIO('hello world'), varname='testfile')]
fp=BytesIO(b'hello world'), varname='testfile')]
formdata.store()
assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1
for subdir in os.listdir(os.path.join(get_publisher().app_dir, 'attachments')):
@ -1616,7 +1616,7 @@ def test_webservice_call(http_requests, pub):
assert attachment.base_filename == 'xxx.xml'
assert attachment.content_type == 'text/xml'
attachment.fp.seek(0)
assert attachment.fp.read(5) == '<?xml'
assert attachment.fp.read(5) == b'<?xml'
formdata.workflow_data = None
item = WebserviceCallStatusItem()
@ -1996,7 +1996,7 @@ def test_webservice_call_store_in_backoffice_filefield(http_requests, pub):
assert attachment.base_filename == 'xxx.xml'
assert attachment.content_type == 'text/xml'
attachment.fp.seek(0)
assert attachment.fp.read(5) == '<?xml'
assert attachment.fp.read(5) == b'<?xml'
# no more 'bo1' backoffice field: do nothing
formdata = formdef.data_class()()
@ -2892,7 +2892,7 @@ def test_geolocate_overwrite(pub):
@pytest.mark.skipif(transform_to_pdf is None, reason='libreoffice not found')
def test_transform_to_pdf():
instream = open(os.path.join(os.path.dirname(__file__), 'template.odt'))
instream = open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb')
outstream = transform_to_pdf(instream)
assert outstream is not False
assert outstream.read(10).startswith('%PDF-')
@ -2919,9 +2919,9 @@ def test_export_to_model_image(pub):
item.convert_to_pdf = False
item.method = 'non-interactive'
template_filename = os.path.join(os.path.dirname(__file__), 'template-with-image.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
item.model_file = UploadedFile(pub.app_dir, None, upload)
@ -2980,9 +2980,9 @@ def test_export_to_model_backoffice_field(pub):
item.method = 'non-interactive'
item.convert_to_pdf = False
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
item.model_file = UploadedFile(pub.app_dir, None, upload)
@ -2995,7 +2995,7 @@ def test_export_to_model_backoffice_field(pub):
assert fbo1.base_filename == 'template.odt'
assert fbo1.content_type == 'application/octet-stream'
zfile = zipfile.ZipFile(fbo1.get_file())
assert 'foo-export-to-bofile' in zfile.read('content.xml')
assert b'foo-export-to-bofile' in zfile.read('content.xml')
# no more 'bo1' backoffice field: do nothing
formdata = formdef.data_class()()
@ -3037,31 +3037,31 @@ def test_export_to_model_django_template(pub):
item.method = 'non-interactive'
item.attach_to_history = True
template_filename = os.path.join(os.path.dirname(__file__), 'template-django.odt')
template = open(template_filename).read()
template = open(template_filename, 'rb').read()
upload = QuixoteUpload('/foo/template-django.odt', content_type='application/octet-stream')
upload.fp = StringIO()
upload.fp = BytesIO()
upload.fp.write(template)
upload.fp.seek(0)
item.model_file = UploadedFile(pub.app_dir, None, upload)
item.convert_to_pdf = False
item.perform(formdata)
new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[0].filename)).read('content.xml')
assert '>foo-export-to-template-with-django<' in new_content
new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[0].filename, 'rb')).read('content.xml')
assert b'>foo-export-to-template-with-django<' in new_content
formdef.name = 'Name with a \' simple quote'
formdef.store()
item.perform(formdata)
new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[1].filename)).read('content.xml')
assert '>Name with a \' simple quote<' in new_content
new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[1].filename, 'rb')).read('content.xml')
assert b'>Name with a \' simple quote<' in new_content
formdef.name = 'A <> name'
formdef.store()
item.perform(formdata)
new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[2].filename)).read('content.xml')
assert '>A &lt;&gt; name<' in new_content
new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[2].filename, 'rb')).read('content.xml')
assert b'>A &lt;&gt; name<' in new_content
def test_global_timeouts(two_pubs):
pub = two_pubs
@ -3543,8 +3543,7 @@ def test_set_backoffice_field_file(http_requests, two_pubs):
formdata = formdef.data_class().get(formdata.id)
assert formdata.data['bo1'].base_filename == 'test2.odt'
assert formdata.data['bo1'].content_type == 'application/vnd.oasis.opendocument.text'
assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__),
'template.odt')).read()
assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb').read()
# check storing response as attachment
two_pubs.substitutions.feed(formdata)