tests: pass bytes to base64 (#36515)

This commit is contained in:
Frédéric Péters 2019-11-13 14:29:40 +01:00
parent 0e01b626b1
commit 1bdd4cfda2
4 changed files with 8 additions and 9 deletions

View File

@ -783,7 +783,7 @@ def test_formdef_submit_with_varname(pub, local_user):
'date': '1970-01-01',
'file': {
'filename': 'test.txt',
'content': base64.b64encode('test'),
'content': base64.b64encode(b'test'),
},
'map': {
'lat': 1.5,
@ -1297,8 +1297,8 @@ def test_formdata_with_workflow_data(pub, local_user):
assert resp.json['workflow']['data']['xxx'] == 23
assert resp.json['workflow']['data']['blah']['filename'] == 'test.txt'
assert resp.json['workflow']['data']['blah']['content_type'] == 'text/plain'
assert base64.decodestring(resp.json['workflow']['data']['blah']['content']) == 'test'
assert base64.decodestring(resp.json['workflow']['data']['blah2']['content']) == 'test'
assert base64.decodestring(force_bytes(resp.json['workflow']['data']['blah']['content'])) == b'test'
assert base64.decodestring(force_bytes(resp.json['workflow']['data']['blah2']['content'])) == b'test'
def test_user_by_nameid(pub, local_user):
resp = get_app(pub).get(sign_uri('/api/users/xyz/', user=local_user),

View File

@ -1,6 +1,7 @@
import base64
import json
from django.utils.encoding import force_bytes
from django.utils.six.moves.urllib import parse as urllib
from django.utils.six.moves.urllib import parse as urlparse
from quixote import cleanup, get_session_manager
@ -48,7 +49,7 @@ PROFILE = {
def base64url_encode(v):
return base64.urlsafe_b64encode(v).strip('=')
return base64.urlsafe_b64encode(force_bytes(v)).strip(b'=')
def setup_module(module):

View File

@ -455,8 +455,6 @@ M. Francis Kuntz
assert 'M. Francis Kuntz' in html
def test_dict_from_prefix():
hello_word_b64 = base64.encodestring('hello world')
d = evalutils.dict_from_prefix('var1', {})
assert d == {}

View File

@ -991,9 +991,9 @@ def test_register_comment_with_attachment_file(pub):
ws_response_varname = 'ws_response_afile'
wf_data = {
'%s_filename' % ws_response_varname : 'hello.txt',
'%s_content_type' % ws_response_varname : 'text/plain',
'%s_b64_content' % ws_response_varname : base64.encodestring('hello world'),
'%s_filename' % ws_response_varname: 'hello.txt',
'%s_content_type' % ws_response_varname: 'text/plain',
'%s_b64_content' % ws_response_varname: base64.encodestring(b'hello world'),
}
formdata.update_workflow_data(wf_data)
formdata.store()