diff options
author | Francesco Panico <panico.francesco@gmail.com> | 2022-11-11 07:17:49 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-10 10:56:59 +0100 |
commit | 72efd840a8cb6ee35a3732d8bb434e7361970b3c (patch) | |
tree | 8379ee124d0c278b593b3dc2487ab8e44ad64c30 /tests/file_uploads | |
parent | 04fdf719331dde6b0f4e7cdc445be4d4278f3ec4 (diff) | |
download | django-72efd840a8cb6ee35a3732d8bb434e7361970b3c.tar.gz |
Fixed #34110 -- Added in-memory file storage.
Thanks Paolo Melchiorre, Carlton Gibson, and Mariusz Felisiak for
reviews.
Diffstat (limited to 'tests/file_uploads')
-rw-r--r-- | tests/file_uploads/tests.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index ecbee48160..f3d926ac5f 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -11,6 +11,7 @@ from urllib.parse import quote from django.core.exceptions import SuspiciousFileOperation from django.core.files import temp as tempfile +from django.core.files.storage import default_storage from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile from django.http.multipartparser import ( FILE, @@ -804,6 +805,9 @@ class DirectoryCreationTests(SimpleTestCase): @unittest.skipIf( sys.platform == "win32", "Python on Windows doesn't have working os.chmod()." ) + @override_settings( + DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage" + ) def test_readonly_root(self): """Permission errors are not swallowed""" os.chmod(MEDIA_ROOT, 0o500) @@ -814,9 +818,11 @@ class DirectoryCreationTests(SimpleTestCase): ) def test_not_a_directory(self): + default_storage.delete(UPLOAD_TO) # Create a file with the upload directory name - open(UPLOAD_TO, "wb").close() - self.addCleanup(os.remove, UPLOAD_TO) + with SimpleUploadedFile(UPLOAD_TO, b"x") as file: + default_storage.save(UPLOAD_TO, file) + self.addCleanup(default_storage.delete, UPLOAD_TO) msg = "%s exists and is not a directory." % UPLOAD_TO with self.assertRaisesMessage(FileExistsError, msg): with SimpleUploadedFile("foo.txt", b"x") as file: |