diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2014-05-25 22:52:47 +0200 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2014-06-11 09:03:11 +0200 |
| commit | 1ff11304dcebbabdede8ef3d659ca0e54055e2fd (patch) | |
| tree | c3924926cdd778492c63059e781c92fee720b9b2 /tests/file_storage | |
| parent | de0e285be80e0ca756088a97335d8faa698fbe6b (diff) | |
[1.7.x] Fixed #22680 -- I/O operation on closed file.
This patch is two-fold; first it ensure that Django does close everything in
request.FILES at the end of the request and secondly the storage system should
no longer close any files during save, it's up to the caller to handle that --
or let Django close the files at the end of the request.
Backport of e2efc8965edf684aaf48621680ef54b84e116576 from master.
Diffstat (limited to 'tests/file_storage')
| -rw-r--r-- | tests/file_storage/tests.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index a0e2e2a6cc..b7e4bcdf6d 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -19,7 +19,8 @@ from django.core.cache import cache from django.core.exceptions import SuspiciousOperation from django.core.files.base import File, ContentFile from django.core.files.storage import FileSystemStorage, get_storage_class -from django.core.files.uploadedfile import SimpleUploadedFile +from django.core.files.uploadedfile import (InMemoryUploadedFile, SimpleUploadedFile, + TemporaryUploadedFile) from django.test import LiveServerTestCase, SimpleTestCase from django.test import override_settings from django.utils import six @@ -206,6 +207,23 @@ class FileStorageTests(unittest.TestCase): self.storage.delete('path/to/test.file') + def test_save_doesnt_close(self): + with TemporaryUploadedFile('test', 'text/plain', 1, 'utf8') as file: + file.write(b'1') + file.seek(0) + self.assertFalse(file.closed) + self.storage.save('path/to/test.file', file) + self.assertFalse(file.closed) + self.assertFalse(file.file.closed) + + file = InMemoryUploadedFile(six.StringIO('1'), '', 'test', + 'text/plain', 1, 'utf8') + with file: + self.assertFalse(file.closed) + self.storage.save('path/to/test.file', file) + self.assertFalse(file.closed) + self.assertFalse(file.file.closed) + def test_file_path(self): """ File storage returns the full path of a file |
