summaryrefslogtreecommitdiff
path: root/tests/files
diff options
context:
space:
mode:
authorHans Lawrenz <hrlawrenz@gmail.com>2014-03-21 10:57:18 -0400
committerBaptiste Mispelon <bmispelon@gmail.com>2014-03-21 22:34:47 +0100
commit918a16bc4c099ab0cae72a231de3e99e2a9d02cb (patch)
tree455dc4e7fa74c3ded2987e53aa438cef544bf170 /tests/files
parent7e0f9095f762a74116b0b4ba0c88267bdf184e0f (diff)
downloaddjango-918a16bc4c099ab0cae72a231de3e99e2a9d02cb.tar.gz
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.
Diffstat (limited to 'tests/files')
-rw-r--r--tests/files/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/files/tests.py b/tests/files/tests.py
index 4f5e171712..be243b2527 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -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)