Add to_str method in python client and add test cases.

This commit is contained in:
geekerzp
2015-07-22 11:00:51 +08:00
parent 68820e5a80
commit b9287cf417
7 changed files with 238 additions and 48 deletions

View File

@@ -18,6 +18,8 @@ Copyright 2015 SmartBear Software
"""
{{#models}}
{{#model}}
from pprint import pformat
from six import iteritems
class {{classname}}(object):
@@ -64,14 +66,37 @@ class {{classname}}(object):
{{/isEnum}}self._{{name}} = {{name}}
{{/vars}}
def __repr__(self):
properties = []
for p in self.__dict__:
if p != 'swaggerTypes' and p != 'attributeMap':
properties.append('{prop}={val!r}'
.format(prop=p, val=self.__dict__[p]))
def to_dict(self):
"""
Return model properties dict
"""
result = {}
return '<{name} {props}>'.format(name=__name__,
props=' '.join(properties))
for name, prop in iteritems(self.__dict__):
if name == "attribute_map" or name == "swagger_types":
continue
if isinstance(prop, list):
result[name[1:]] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
prop
))
elif hasattr(prop, "to_dict"):
result[name[1:]] = prop.to_dict()
else:
result[name[1:]] = prop
return result
def to_str(self):
"""
Return model properties str
"""
return pformat(self.to_dict())
def __repr__(self):
"""
For `print` and `pprint`
"""
return self.to_str()
{{/model}}
{{/models}}