misc: pass bytes to base64 in utils.attachment() function (#36515)
This commit is contained in:
parent
96bf98cd7c
commit
1ec58ee869
|
@ -1386,8 +1386,8 @@ def test_email_attachments(pub, emails):
|
|||
assert emails.emails['foobar']['msg'].get_payload(2).get_content_type() == 'application/json'
|
||||
payload1 = emails.emails['foobar']['msg'].get_payload(1)
|
||||
payload2 = emails.emails['foobar']['msg'].get_payload(2)
|
||||
assert payload1.get_payload(decode=True) == "Hello world"
|
||||
assert json.loads(payload2.get_payload(decode=True)) == {'hello': 'world'}
|
||||
assert payload1.get_payload(decode=True) == b"Hello world"
|
||||
assert json.loads(force_text(payload2.get_payload(decode=True))) == {'hello': 'world'}
|
||||
|
||||
|
||||
def test_webservice_call(http_requests, pub):
|
||||
|
|
|
@ -24,6 +24,9 @@ import datetime
|
|||
import re
|
||||
import time
|
||||
|
||||
from django.utils.encoding import force_bytes
|
||||
|
||||
from wcs.qommon import force_str
|
||||
from .misc import get_as_datetime
|
||||
|
||||
today = datetime.date.today
|
||||
|
@ -135,7 +138,7 @@ def attachment(content, filename='', content_type='application/octet-stream'):
|
|||
return {
|
||||
'filename': filename,
|
||||
'content_type': content_type,
|
||||
'b64_content': base64.b64encode(content),
|
||||
'b64_content': force_str(base64.b64encode(force_bytes(content))),
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue