Fix to_dict not converting enums to strings

Fixes #28
This commit is contained in:
Jason Paryani
2014-06-26 00:53:16 -07:00
parent 73492b21ce
commit 3a0eaacc9d
2 changed files with 11 additions and 0 deletions

View File

@@ -735,6 +735,9 @@ cdef _to_dict(msg, bint verbose):
return ret
if msg_type is _DynamicEnum:
return str(msg)
return msg

View File

@@ -171,3 +171,11 @@ def test_set_dict_union(addressbook):
person = addressbook.Person.new_message(**{'employment': {'employer': {'name': 'foo'}}})
assert person.employment.employer.name == 'foo'
def test_to_dict_enum(addressbook):
person = addressbook.Person.new_message(**{'phones': [{'number': '999-9999', 'type': 'mobile'}]})
field = person.to_dict()['phones'][0]['type']
assert isinstance(field, basestring)
assert field == 'mobile'