From a9d03c409406f3f95f692bc5545ebacc7f4e2e4f Mon Sep 17 00:00:00 2001 From: Gaƫl Utard Date: Sat, 15 Feb 2025 15:55:33 +0100 Subject: [5.1.x] Fixed #36191 -- Truncated the overwritten file content in FileSystemStorage. Backport of 0d1dd6bba0c18b7feb6caa5cbd8df80fbac54afd from main. --- tests/file_storage/tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 9b643128d1..7f0a68b0c5 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -704,6 +704,18 @@ class OverwritingStorageTests(FileStorageTests): finally: self.storage.delete(name) + def test_save_overwrite_behavior_truncate(self): + name = "test.file" + original_content = b"content extra extra extra" + new_smaller_content = b"content" + self.storage.save(name, ContentFile(original_content)) + try: + self.storage.save(name, ContentFile(new_smaller_content)) + with self.storage.open(name) as fp: + self.assertEqual(fp.read(), new_smaller_content) + finally: + self.storage.delete(name) + def test_save_overwrite_behavior_temp_file(self): """Saving to same file name twice overwrites the first file.""" name = "test.file" -- cgit v1.3