add tests for file types and fix a python 3 issue with handling files coming from fieldstorage objects
This commit is contained in:
parent
003fed76a3
commit
a896345971
@ -427,3 +427,36 @@ class TestTypes(unittest.TestCase):
|
|||||||
a.datatype = [weakref.ref(int)]
|
a.datatype = [weakref.ref(int)]
|
||||||
assert isinstance(a.datatype, list)
|
assert isinstance(a.datatype, list)
|
||||||
assert a.datatype[0] is int
|
assert a.datatype[0] is int
|
||||||
|
|
||||||
|
def test_file_get_content_by_reading(self):
|
||||||
|
class buffer:
|
||||||
|
def read(self):
|
||||||
|
return 'abcdef'
|
||||||
|
f = types.File(file=buffer())
|
||||||
|
assert f.content == 'abcdef'
|
||||||
|
|
||||||
|
def test_file_content_overrides_file(self):
|
||||||
|
class buffer:
|
||||||
|
def read(self):
|
||||||
|
return 'from-file'
|
||||||
|
f = types.File(content='from-content', file=buffer())
|
||||||
|
assert f.content == 'from-content'
|
||||||
|
|
||||||
|
def test_file_setting_content_discards_file(self):
|
||||||
|
class buffer:
|
||||||
|
def read(self):
|
||||||
|
return 'from-file'
|
||||||
|
f = types.File(file=buffer())
|
||||||
|
f.content = 'from-content'
|
||||||
|
assert f.content == 'from-content'
|
||||||
|
|
||||||
|
def test_file_field_storage(self):
|
||||||
|
class buffer:
|
||||||
|
def read(self):
|
||||||
|
return 'from-file'
|
||||||
|
class fieldstorage:
|
||||||
|
filename = 'static.json'
|
||||||
|
file = buffer()
|
||||||
|
type = 'application/json'
|
||||||
|
f = types.File(fieldstorage=fieldstorage)
|
||||||
|
assert f.content == 'from-file'
|
||||||
|
@ -583,7 +583,7 @@ class File(Base):
|
|||||||
if fieldstorage.file:
|
if fieldstorage.file:
|
||||||
self._file = fieldstorage.file
|
self._file = fieldstorage.file
|
||||||
self.filename = fieldstorage.filename
|
self.filename = fieldstorage.filename
|
||||||
self.contenttype = unicode(fieldstorage.type)
|
self.contenttype = text(fieldstorage.type)
|
||||||
else:
|
else:
|
||||||
self._content = fieldstorage.value
|
self._content = fieldstorage.value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user