handle binary/text when using file (#40572)
This commit is contained in:
parent
79f8e67f78
commit
406bea83ca
|
@ -36,7 +36,7 @@ def push_document(signal, sender, instance, **kwargs):
|
|||
json_name = name + '.json'
|
||||
path = os.path.join(app_settings.PFWB_GED_DIRECTORY, name)
|
||||
path_json = os.path.join(app_settings.PFWB_GED_DIRECTORY, json_name)
|
||||
with open(path, 'w') as f:
|
||||
with open(path, 'wb') as f:
|
||||
f.write(attached_file.content.read())
|
||||
with open(path_json, 'w') as f:
|
||||
f.write(json.dumps(metadata))
|
||||
|
|
|
@ -10,7 +10,7 @@ import sys
|
|||
from contextlib import contextmanager
|
||||
from functools import wraps
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.six import StringIO
|
||||
|
||||
|
||||
|
@ -107,7 +107,7 @@ class SendMailTestCase(TestCase):
|
|||
'subject': subject
|
||||
}
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
f.write(content)
|
||||
f.write(force_bytes(content))
|
||||
f.flush()
|
||||
management.call_command('sendmail', recipient_email, file=f.name,
|
||||
sender=expedition_email)
|
||||
|
@ -264,7 +264,7 @@ class SendMailAttachedFileTestCase(TestCase):
|
|||
msg.add_header('Content-Disposition', 'attachment', filename=filename)
|
||||
encoders.encode_base64(msg)
|
||||
message.attach(msg)
|
||||
return message.as_string()
|
||||
return force_bytes(message.as_string())
|
||||
|
||||
@stderr_output('')
|
||||
def test_attached_file1(self):
|
||||
|
@ -284,7 +284,7 @@ class SendMailAttachedFileTestCase(TestCase):
|
|||
self.assertEquals(document.comment, 'coucou')
|
||||
self.assertEquals(document.attached_files.get().name, 'attached-file')
|
||||
self.assertEquals(document.attached_files.get().content.read(),
|
||||
'content')
|
||||
b'content')
|
||||
self.assertEquals(document.to_user.count(), 1)
|
||||
self.assertEquals(document.to_list.count(), 0)
|
||||
self.assertEquals(document.to_user.get(), self.to_user)
|
||||
|
|
Loading…
Reference in New Issue