mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #22307 -- Fixed SpooledTemporaryFile bug in File class.
Added condition to prevent checking the existence of a file name of a file like object when the name attribute is None. This is necessary because a SpooledTemporaryFile won't exist on the file system or have a name until it has reached its max_size. Also added tests.
This commit is contained in:
parent
7e0f9095f7
commit
918a16bc4c
2 changed files with 15 additions and 1 deletions
|
@ -205,3 +205,17 @@ class FileMoveSafeTests(unittest.TestCase):
|
|||
|
||||
os.close(handle_a)
|
||||
os.close(handle_b)
|
||||
|
||||
|
||||
class SpooledTempTests(unittest.TestCase):
|
||||
def test_in_memory_spooled_temp(self):
|
||||
with tempfile.SpooledTemporaryFile() as temp:
|
||||
temp.write(b"foo bar baz quux\n")
|
||||
django_file = File(temp, name="something.txt")
|
||||
self.assertEqual(django_file.size, 17)
|
||||
|
||||
def test_written_spooled_temp(self):
|
||||
with tempfile.SpooledTemporaryFile(max_size=4) as temp:
|
||||
temp.write(b"foo bar baz quux\n")
|
||||
django_file = File(temp, name="something.txt")
|
||||
self.assertEqual(django_file.size, 17)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue