Allow File-like objects to be stored.
No longer demands FileField be an actual instance of file, but instead checks whether object has a 'read' attribute. Fixes read() on GridFSProxy to return an empty string on read failure, or None if file does not exist.
This commit is contained in:
parent
5f4b70f3a9
commit
c474ca0f13
2 changed files with 24 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ import datetime
|
|||
import os
|
||||
import unittest
|
||||
import uuid
|
||||
import StringIO
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
|
|
@ -1481,6 +1482,21 @@ class FieldTest(unittest.TestCase):
|
|||
self.assertEquals(result.file.read(), text)
|
||||
self.assertEquals(result.file.content_type, content_type)
|
||||
result.file.delete() # Remove file from GridFS
|
||||
PutFile.objects.delete()
|
||||
|
||||
# Ensure file-like objects are stored
|
||||
putfile = PutFile()
|
||||
putstring = StringIO.StringIO()
|
||||
putstring.write(text)
|
||||
putstring.seek(0)
|
||||
putfile.file.put(putstring, content_type=content_type)
|
||||
putfile.save()
|
||||
putfile.validate()
|
||||
result = PutFile.objects.first()
|
||||
self.assertTrue(putfile == result)
|
||||
self.assertEquals(result.file.read(), text)
|
||||
self.assertEquals(result.file.content_type, content_type)
|
||||
result.file.delete()
|
||||
|
||||
streamfile = StreamFile()
|
||||
streamfile.file.new_file(content_type=content_type)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue