tests: give bytes to Upload (#36515)
This commit is contained in:
parent
e4333e6719
commit
a295a0b441
|
@ -836,7 +836,7 @@ def test_formdef_submit_from_wscall(pub, local_user):
|
|||
formdata.just_created()
|
||||
|
||||
upload = PicklableUpload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['test'])
|
||||
upload.receive([b'test'])
|
||||
|
||||
formdata.data = {
|
||||
'0': 'xxx',
|
||||
|
@ -1131,7 +1131,7 @@ def test_formdata(pub, local_user):
|
|||
formdata = formdef.data_class()()
|
||||
date = time.strptime('2014-01-20', '%Y-%m-%d')
|
||||
upload = PicklableUpload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['base64me'])
|
||||
upload.receive([b'base64me'])
|
||||
formdata.data = {
|
||||
'0': 'foo@localhost',
|
||||
'1': 'xxx',
|
||||
|
@ -1285,9 +1285,9 @@ def test_formdata_with_workflow_data(pub, local_user):
|
|||
|
||||
from wcs.qommon.form import PicklableUpload as PicklableUpload3
|
||||
upload = PicklableUpload3('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['test'])
|
||||
upload.receive([b'test'])
|
||||
upload2 = PicklableUpload3('test.txt', 'text/plain', 'ascii')
|
||||
upload2.receive(['test'])
|
||||
upload2.receive([b'test'])
|
||||
formdata.workflow_data = {'blah': upload, 'blah2': upload2, 'xxx': 23}
|
||||
formdata.store()
|
||||
|
||||
|
@ -1537,7 +1537,7 @@ def test_user_drafts(pub, local_user):
|
|||
|
||||
formdata = formdef.data_class()()
|
||||
upload = PicklableUpload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['base64me'])
|
||||
upload.receive([b'base64me'])
|
||||
formdata.data = {'0': 'foo@localhost', '1': 'xxx', '2': upload}
|
||||
formdata.user_id = local_user.id
|
||||
formdata.page_no = 1
|
||||
|
@ -1603,7 +1603,7 @@ def test_api_list_formdata(pub, local_user):
|
|||
formdata = data_class()
|
||||
date = time.strptime('2014-01-20', '%Y-%m-%d')
|
||||
upload = PicklableUpload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['base64me'])
|
||||
upload.receive([b'base64me'])
|
||||
formdata.data = {'0': 'FOO BAR %d' % i, '2': upload}
|
||||
formdata.user_id = local_user.id
|
||||
if i%4 == 0:
|
||||
|
@ -1724,7 +1724,7 @@ def test_api_anonymized_formdata(pub, local_user, admin_user):
|
|||
formdata = data_class()
|
||||
date = time.strptime('2014-01-20', '%Y-%m-%d')
|
||||
upload = PicklableUpload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['base64me'])
|
||||
upload.receive([b'base64me'])
|
||||
formdata.data = {'0': 'FOO BAR %d' % i, '2': upload}
|
||||
formdata.user_id = local_user.id
|
||||
if i%4 == 0:
|
||||
|
@ -1831,7 +1831,7 @@ def test_api_geojson_formdata(pub, local_user):
|
|||
resp = get_app(pub).get(sign_uri('/api/forms/test/geojson?anonymise', user=local_user), status=403)
|
||||
|
||||
upload = PicklableUpload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['base64me'])
|
||||
upload.receive([b'base64me'])
|
||||
|
||||
foobar = '<font color="red">FOO BAR</font>'
|
||||
username = '<font color="red">Jean Darmette</font>'
|
||||
|
|
|
@ -568,7 +568,7 @@ def test_backoffice_image_column(pub):
|
|||
formdef.store()
|
||||
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
jpg = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
|
||||
jpg = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
upload.receive([jpg])
|
||||
for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
|
||||
formdata.data['4'] = upload
|
||||
|
@ -891,7 +891,7 @@ def test_backoffice_ods(pub):
|
|||
|
||||
formdata = formdef.data_class().select(lambda x: x.status == 'wf-new')[0]
|
||||
formdata.data['4'] = PicklableUpload('/foo/bar', content_type='text/plain')
|
||||
formdata.data['4'].receive(['hello world'])
|
||||
formdata.data['4'].receive([b'hello world'])
|
||||
formdata.data['5'] = time.strptime('2015-05-12', '%Y-%m-%d')
|
||||
formdata.data['6'] = '12345'
|
||||
formdata.data['7'] = '0102030405'
|
||||
|
|
|
@ -162,7 +162,7 @@ def test_file_field(pub):
|
|||
formdef.store()
|
||||
formdata = formdef.data_class()()
|
||||
upload = Upload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['first line', 'second line'])
|
||||
upload.receive([b'first line', b'second line'])
|
||||
formdata.data = {'0': upload}
|
||||
formdata.id = 1
|
||||
substvars = formdata.get_substitution_variables()
|
||||
|
@ -478,7 +478,7 @@ def test_backoffice_field_varname(pub):
|
|||
|
||||
def test_workflow_data_file_url(pub):
|
||||
upload = Upload('test.txt', 'text/plain', 'ascii')
|
||||
upload.receive(['first line', 'second line'])
|
||||
upload.receive([b'first line', b'second line'])
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.store()
|
||||
|
@ -588,7 +588,7 @@ def variable_test_data(pub):
|
|||
'11': '4',
|
||||
'12': '3.14',
|
||||
}
|
||||
formdata.data['5'].receive(['hello world'])
|
||||
formdata.data['5'].receive([b'hello world'])
|
||||
formdata.geolocations = {'base': {'lat': 1, 'lon': 2}}
|
||||
formdata.store()
|
||||
pub.substitutions.feed(pub)
|
||||
|
|
|
@ -264,7 +264,7 @@ def test_unused_file_removal_job(pub):
|
|||
formdata.data = {
|
||||
'5': PicklableUpload('test.txt', 'text/plain'),
|
||||
}
|
||||
formdata.data['5'].receive(['hello world'])
|
||||
formdata.data['5'].receive([b'hello world'])
|
||||
formdata.store()
|
||||
|
||||
assert formdata.data['5'].qfilename in os.listdir(os.path.join(pub.app_dir, 'uploads'))
|
||||
|
@ -285,7 +285,7 @@ def test_unused_file_removal_job(pub):
|
|||
formdata.data = {
|
||||
'5': PicklableUpload('test.txt', 'text/plain'),
|
||||
}
|
||||
formdata.data['5'].receive(['hello world'])
|
||||
formdata.data['5'].receive([b'hello world'])
|
||||
formdata.store()
|
||||
|
||||
assert formdata.data['5'].qfilename in os.listdir(os.path.join(pub.app_dir, 'uploads'))
|
||||
|
@ -301,7 +301,7 @@ def test_unused_file_removal_job(pub):
|
|||
formdata.data = {
|
||||
'5': PicklableUpload('test.txt', 'text/plain'),
|
||||
}
|
||||
formdata.data['5'].receive(['hello world'])
|
||||
formdata.data['5'].receive([b'hello world'])
|
||||
formdata.store()
|
||||
|
||||
# same file, deduplicated
|
||||
|
@ -324,7 +324,7 @@ def test_unused_file_removal_job(pub):
|
|||
workflow.store()
|
||||
formdef.workflow = workflow
|
||||
formdef.workflow_options = {'1': PicklableUpload('test.txt', 'text/plain')}
|
||||
formdef.workflow_options['1'].receive(['hello world'])
|
||||
formdef.workflow_options['1'].receive([b'hello world'])
|
||||
formdef.store()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
|
@ -332,7 +332,7 @@ def test_unused_file_removal_job(pub):
|
|||
formdata.data = {
|
||||
'5': PicklableUpload('test.txt', 'text/plain'),
|
||||
}
|
||||
formdata.data['5'].receive(['hello world'])
|
||||
formdata.data['5'].receive([b'hello world'])
|
||||
formdata.store()
|
||||
|
||||
assert len(os.listdir(os.path.join(pub.app_dir, 'uploads'))) == 1
|
||||
|
@ -372,7 +372,7 @@ def test_unused_file_removal_job(pub):
|
|||
user = pub.user_class()
|
||||
user.email = 'bar@localhost'
|
||||
user.form_data = {'3': PicklableUpload('test.txt', 'text/plain')}
|
||||
user.form_data['3'].receive(['hello world 2'])
|
||||
user.form_data['3'].receive([b'hello world 2'])
|
||||
user.store()
|
||||
|
||||
assert len(os.listdir(os.path.join(pub.app_dir, 'uploads'))) == 1
|
||||
|
|
|
@ -330,12 +330,12 @@ def test_email_plain_with_attachments(emails):
|
|||
pub = create_temporary_pub()
|
||||
|
||||
jpg = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
jpg_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
|
||||
jpg_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
jpg.receive([jpg_content])
|
||||
txt = PicklableUpload('test.txt', 'text/plain')
|
||||
txt.receive(['foo-text-bar'])
|
||||
txt.receive([b'foo-text-bar'])
|
||||
odt = PicklableUpload('test.odt', 'application/vnd.oasis.opendocument.text')
|
||||
odt_content = open(os.path.join(os.path.dirname(__file__), 'template.odt')).read()
|
||||
odt_content = open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb').read()
|
||||
odt.receive([odt_content])
|
||||
|
||||
send_email('jpg', mail_body='Hello',
|
||||
|
@ -369,7 +369,7 @@ def test_email_plain_with_attachments(emails):
|
|||
assert base64.b64decode(emails.emails['jpgodt']['msg'].get_payload()[2].get_payload()) == odt_content
|
||||
|
||||
unknown = PicklableUpload('test.eo', 'x-foo/x-bar')
|
||||
unknown.receive(['barfoo'])
|
||||
unknown.receive([b'barfoo'])
|
||||
send_email('unknown', mail_body='Hello',
|
||||
email_rcpt='test@localhost', want_html=False,
|
||||
attachments=[unknown])
|
||||
|
@ -391,7 +391,7 @@ def test_email_plain_and_html_with_attachments(emails):
|
|||
pub = create_temporary_pub()
|
||||
pub.cfg['emails'] = {'footer': 'Footer\nText'}
|
||||
jpg = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
jpg_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
|
||||
jpg_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
jpg.receive([jpg_content])
|
||||
|
||||
send_email('test', mail_body='Hello', email_rcpt='test@localhost', attachments=[jpg])
|
||||
|
|
|
@ -936,7 +936,7 @@ def test_register_comment_with_attachment_file(pub):
|
|||
wf.store()
|
||||
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
jpg = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
|
||||
jpg = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
upload.receive([jpg])
|
||||
|
||||
formdef = FormDef()
|
||||
|
@ -1259,7 +1259,7 @@ def test_email_attachments(pub, emails):
|
|||
formdef.store()
|
||||
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
jpg = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
|
||||
jpg = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
upload.receive([jpg])
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'3': upload}
|
||||
|
@ -2791,7 +2791,7 @@ def test_geolocate_image(pub):
|
|||
formdef.store()
|
||||
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
upload.receive([open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()])
|
||||
upload.receive([open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()])
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'3': upload}
|
||||
|
@ -2821,7 +2821,7 @@ def test_geolocate_image(pub):
|
|||
|
||||
# invalid photo
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
upload.receive([open(os.path.join(os.path.dirname(__file__), 'template.odt')).read()])
|
||||
upload.receive([open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb').read()])
|
||||
formdata.data = {'3': upload}
|
||||
formdata.geolocations = None
|
||||
item.perform(formdata)
|
||||
|
@ -2906,7 +2906,7 @@ def test_export_to_model_image(pub):
|
|||
formdef.store()
|
||||
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
image_data = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
|
||||
image_data = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
upload.receive([image_data])
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
|
@ -3514,7 +3514,7 @@ def test_set_backoffice_field_file(http_requests, two_pubs):
|
|||
|
||||
# store a PiclableUpload
|
||||
upload = PicklableUpload('test.jpeg', 'image/jpeg')
|
||||
upload.receive([open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()])
|
||||
upload.receive([open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()])
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'00': upload}
|
||||
|
@ -3527,13 +3527,12 @@ def test_set_backoffice_field_file(http_requests, two_pubs):
|
|||
formdata = formdef.data_class().get(formdata.id)
|
||||
assert formdata.data['bo1'].base_filename == 'test.jpeg'
|
||||
assert formdata.data['bo1'].content_type == 'image/jpeg'
|
||||
assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__),
|
||||
'image-with-gps-data.jpeg')).read()
|
||||
assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
|
||||
|
||||
# same test with PicklableUpload wcs.qommon.form
|
||||
from wcs.qommon.form import PicklableUpload as PicklableUpload2
|
||||
upload2 = PicklableUpload2('test2.odt', 'application/vnd.oasis.opendocument.text')
|
||||
upload2.receive([open(os.path.join(os.path.dirname(__file__), 'template.odt')).read()])
|
||||
upload2.receive([open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb').read()])
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'00': upload2}
|
||||
formdata.just_created()
|
||||
|
|
Loading…
Reference in New Issue