tests: pass binary data to atomic_write (#38781)
This commit is contained in:
parent
d96495ea43
commit
4138a92412
|
@ -15,10 +15,11 @@
|
|||
|
||||
import os
|
||||
|
||||
from django.core.files.storage import default_storage
|
||||
from django.utils.encoding import force_bytes
|
||||
import pytest
|
||||
|
||||
from passerelle.utils.files import atomic_write
|
||||
from django.core.files.storage import default_storage
|
||||
|
||||
|
||||
def test_atomic_write(tmpdir):
|
||||
|
@ -27,7 +28,7 @@ def test_atomic_write(tmpdir):
|
|||
|
||||
with pytest.raises(Exception):
|
||||
with atomic_write(filepath) as fd:
|
||||
fd.write('coucou')
|
||||
fd.write(force_bytes('coucou'))
|
||||
raise Exception()
|
||||
|
||||
assert not os.path.exists(filepath)
|
||||
|
@ -39,8 +40,7 @@ def test_atomic_write(tmpdir):
|
|||
filepath = os.path.join(target_dir, 'test')
|
||||
|
||||
with atomic_write(filepath) as fd:
|
||||
fd.write('coucou')
|
||||
|
||||
fd.write(force_bytes('coucou'))
|
||||
assert os.path.exists(filepath)
|
||||
with open(filepath) as fd:
|
||||
assert fd.read() == 'coucou'
|
||||
|
|
Loading…
Reference in New Issue