Fixed #26398 -- Made FieldFile.open() respect its mode argument.

This commit is contained in:
Alexey Kotlyarov 2016-03-23 09:33:35 +11:00 committed by Tim Graham
parent 9390da7fb6
commit a52a531a8b
2 changed files with 13 additions and 4 deletions

View file

@ -710,6 +710,16 @@ class FileFieldStorageTests(TestCase):
self.assertEqual(list(obj.normal.chunks(chunk_size=2)), [b"co", b"nt", b"en", b"t"])
obj.normal.close()
def test_filefield_write(self):
# Files can be written to.
obj = Storage.objects.create(normal=SimpleUploadedFile('rewritten.txt', b'content'))
with obj.normal as normal:
normal.open('wb')
normal.write(b'updated')
obj.refresh_from_db()
self.assertEqual(obj.normal.read(), b'updated')
obj.normal.close()
def test_duplicate_filename(self):
# Multiple files with the same name get _(7 random chars) appended to them.
objs = [Storage() for i in range(2)]