Fix unicode as object type (#222)
* Fix unicode as object type * Changelog
This commit is contained in:
Родитель
118735008c
Коммит
e813e066fe
|
@ -26,6 +26,7 @@ Release History
|
|||
**Bugfixes**
|
||||
|
||||
- Fix serialization of random Model object #220
|
||||
- Fix serialization of unicode string in Py2 and object mode #221
|
||||
|
||||
|
||||
2020-07-27 Version 0.6.18
|
||||
|
|
|
@ -951,6 +951,8 @@ class Serializer(object):
|
|||
return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs)
|
||||
if obj_type is _long_type:
|
||||
return self.serialize_long(attr)
|
||||
if obj_type is unicode_str:
|
||||
return self.serialize_unicode(attr)
|
||||
|
||||
# If it's a model or I know this dependency, serialize as a Model
|
||||
elif obj_type in self.dependencies.values() or isinstance(attr, Model):
|
||||
|
|
|
@ -1366,6 +1366,8 @@ class TestRuntimeSerialized(unittest.TestCase):
|
|||
except NameError:
|
||||
long_type = int
|
||||
|
||||
s = Serializer()
|
||||
assert s.serialize_data(long_type(1), 'object') == long_type(1)
|
||||
|
||||
class TestModel(Model):
|
||||
_attribute_map = {'data': {'key': 'data', 'type': 'object'}}
|
||||
|
@ -1376,6 +1378,23 @@ class TestRuntimeSerialized(unittest.TestCase):
|
|||
'data': {'id': long_type(1)}
|
||||
}
|
||||
|
||||
def test_unicode_as_type_object(self):
|
||||
"""Test irrelevant on Python 3. But still doing it to test regresssion.
|
||||
https://github.com/Azure/msrest-for-python/issue/221
|
||||
"""
|
||||
|
||||
s = Serializer()
|
||||
assert s.serialize_data(u"\ua015", 'object') == u"\ua015"
|
||||
|
||||
class TestModel(Model):
|
||||
_attribute_map = {'data': {'key': 'data', 'type': 'object'}}
|
||||
|
||||
m = TestModel(data = {'id': u"\ua015"})
|
||||
serialized = m.serialize()
|
||||
assert serialized == {
|
||||
'data': {'id': u"\ua015"}
|
||||
}
|
||||
|
||||
def test_json_with_xml_map(self):
|
||||
basic_json = {'age': 37, 'country': 'france'}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче