Fix serialization from dict if datetime given
This commit is contained in:
Родитель
4de9e1d798
Коммит
c7b9c7ed6d
|
@ -30,6 +30,7 @@ Release History
|
|||
**Bugfixes**
|
||||
|
||||
- Fix minimal dependency of isodate
|
||||
- Fix serialisation from dict if datetime provided
|
||||
|
||||
2018-01-08 Version 0.4.25
|
||||
+++++++++++++++++++++++++
|
||||
|
|
|
@ -954,7 +954,8 @@ class Deserializer(object):
|
|||
'{}': self.deserialize_dict
|
||||
}
|
||||
self.deserialize_expected_types = {
|
||||
'duration': (isodate.Duration, datetime.timedelta)
|
||||
'duration': (isodate.Duration, datetime.timedelta),
|
||||
'iso-8601': (datetime.datetime)
|
||||
}
|
||||
self.dependencies = dict(classes) if classes else {}
|
||||
self.key_extractors = [
|
||||
|
|
|
@ -790,6 +790,24 @@ class TestRuntimeSerialized(unittest.TestCase):
|
|||
with self.assertRaises(SerializationError):
|
||||
self.s.serialize_iter("I am a string", 'str')
|
||||
|
||||
def test_serialize_from_dict_datetime(self):
|
||||
class DateTimeTest(Model):
|
||||
_attribute_map = {
|
||||
'birthday':{'key':'birthday','type':'iso-8601'},
|
||||
}
|
||||
def __init__(self, birthday):
|
||||
self.birthday = birthday
|
||||
|
||||
serializer = Serializer({
|
||||
'DateTimeTest': DateTimeTest
|
||||
})
|
||||
|
||||
mydate = serializer.body(
|
||||
{'birthday': datetime(1980, 12, 27)},
|
||||
'DateTimeTest'
|
||||
)
|
||||
assert mydate["birthday"] == "1980-12-27T00:00:00.000Z"
|
||||
|
||||
def test_serialize_json_obj(self):
|
||||
|
||||
class ComplexId(Model):
|
||||
|
|
Загрузка…
Ссылка в новой задаче