summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHonza Král <Honza.Kral@gmail.com>2013-02-23 08:04:41 -0800
committerHonza Král <Honza.Kral@gmail.com>2013-02-23 08:04:41 -0800
commit129d2e8f85b1e80f10ec967b72ba0af9b239019f (patch)
tree25efef264d89b33ebc6a8bd59ececeb314910c30 /tests
parent8c1cc4b3b04f639ae40bc806380bc4a9dd568eb0 (diff)
parent664855b74e1f417384dc7aef35a3df5f86db52d6 (diff)
Merge pull request #775 from HiddenData/ticket-18899
Fixed #18899 -- FileSystemStorage.save should support any file-like objects
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/files/tests.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/modeltests/files/tests.py b/tests/modeltests/files/tests.py
index 50d1915c28..8fbdbb8ff3 100644
--- a/tests/modeltests/files/tests.py
+++ b/tests/modeltests/files/tests.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import
import gzip
import shutil
+import StringIO
import tempfile
from django.core.cache import cache
@@ -102,6 +103,35 @@ class FileStorageTests(TestCase):
obj4.random.save("random_file", ContentFile("random content"))
self.assertTrue(obj4.random.name.endswith("/random_file"))
+ def test_file_object(self):
+ # Create sample file
+ temp_storage.save('tests/example.txt', ContentFile('some content'))
+
+ # Load it as python file object
+ file_obj = open(temp_storage.path('tests/example.txt'))
+
+ # Save it using storage and read its content
+ temp_storage.save('tests/file_obj', file_obj)
+ self.assertTrue(temp_storage.exists('tests/file_obj'))
+ self.assertEqual(
+ temp_storage.open('tests/file_obj').read(),
+ 'some content')
+
+
+ def test_stringio(self):
+ # Test passing StringIO instance as content argument to save
+ output = StringIO.StringIO()
+ output.write('content')
+ output.seek(0)
+
+ # Save it and read written file
+ temp_storage.save('tests/stringio', output)
+ self.assertTrue(temp_storage.exists('tests/stringio'))
+ self.assertEqual(
+ temp_storage.open('tests/stringio').read(),
+ 'content')
+
+
class FileTests(unittest.TestCase):
def test_context_manager(self):