mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #26495 -- Added name arg to Storage.save()'s File wrapping.
This commit is contained in:
parent
65006e0b0b
commit
4d1c229ee5
2 changed files with 24 additions and 1 deletions
|
@ -644,6 +644,29 @@ class CustomStorageLegacyDatetimeHandlingTests(FileStorageTests):
|
|||
storage_class = CustomStorageLegacyDatetimeHandling
|
||||
|
||||
|
||||
class DiscardingFalseContentStorage(FileSystemStorage):
|
||||
def _save(self, name, content):
|
||||
if content:
|
||||
return super(DiscardingFalseContentStorage, self)._save(name, content)
|
||||
return ''
|
||||
|
||||
|
||||
class DiscardingFalseContentStorageTests(FileStorageTests):
|
||||
storage_class = DiscardingFalseContentStorage
|
||||
|
||||
def test_custom_storage_discarding_empty_content(self):
|
||||
"""
|
||||
When Storage.save() wraps a file-like object in File, it should include
|
||||
the name argument so that bool(file) evaluates to True (#26495).
|
||||
"""
|
||||
output = six.StringIO('content')
|
||||
self.storage.save('tests/stringio', output)
|
||||
self.assertTrue(self.storage.exists('tests/stringio'))
|
||||
|
||||
with self.storage.open('tests/stringio') as f:
|
||||
self.assertEqual(f.read(), b'content')
|
||||
|
||||
|
||||
class FileFieldStorageTests(TestCase):
|
||||
def tearDown(self):
|
||||
shutil.rmtree(temp_storage_location)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue