Handle bool from xml properly; add setbool and getbool unit tests.
--HG-- branch : bool_fromsoap
This commit is contained in:
parent
76bfc4cc70
commit
62b0035ea7
@ -186,6 +186,13 @@ def array_fromxml(datatype, element):
|
||||
]
|
||||
|
||||
|
||||
@fromxml.when_object(bool)
|
||||
def bool_fromxml(datatype, element):
|
||||
if element.get('nil') == 'true':
|
||||
return None
|
||||
return element.text.lower() != 'false'
|
||||
|
||||
|
||||
@fromxml.when_type(wsme.types.DictType)
|
||||
def dict_fromxml(datatype, element):
|
||||
if element.get('nil') == 'true':
|
||||
|
@ -100,6 +100,14 @@ class ReturnTypes(object):
|
||||
def getdate(self):
|
||||
return datetime.date(1994, 1, 26)
|
||||
|
||||
@expose(bool)
|
||||
def getbooltrue(self):
|
||||
return True
|
||||
|
||||
@expose(bool)
|
||||
def getboolfalse(self):
|
||||
return False
|
||||
|
||||
@expose(datetime.time)
|
||||
def gettime(self):
|
||||
return datetime.time(12, 0, 0)
|
||||
@ -388,6 +396,14 @@ class ProtocolTestCase(unittest.TestCase):
|
||||
r = self.call('returntypes/getdecimal')
|
||||
assert r in (decimal.Decimal('3.14159265'), '3.14159265'), r
|
||||
|
||||
def test_return_bool_true(self):
|
||||
r = self.call('returntypes/getbooltrue', _rt=bool)
|
||||
assert r
|
||||
|
||||
def test_return_bool_false(self):
|
||||
r = self.call('returntypes/getboolfalse', _rt=bool)
|
||||
assert not r
|
||||
|
||||
def test_return_date(self):
|
||||
r = self.call('returntypes/getdate')
|
||||
assert r == datetime.date(1994, 1, 26) or r == '1994-01-26', r
|
||||
@ -467,6 +483,14 @@ class ProtocolTestCase(unittest.TestCase):
|
||||
assert self.call('argtypes/setfloat', value=3.54,
|
||||
_rt=float) == 3.54
|
||||
|
||||
def test_setbool_true(self):
|
||||
r = self.call('argtypes/setbool', value=True, _rt=bool)
|
||||
assert r
|
||||
|
||||
def test_setbool_false(self):
|
||||
r = self.call('argtypes/setbool', value=False, _rt=bool)
|
||||
assert not r
|
||||
|
||||
def test_setdecimal(self):
|
||||
value = decimal.Decimal('3.14')
|
||||
assert self.call('argtypes/setdecimal', value=value,
|
||||
|
@ -36,7 +36,7 @@ def dumpxml(key, obj, datatype=None):
|
||||
el.text = obj.decode('ascii')
|
||||
elif isinstance(obj, wsme.types.text):
|
||||
el.text = obj
|
||||
elif type(obj) in (int, float, decimal.Decimal):
|
||||
elif type(obj) in (int, float, bool, decimal.Decimal):
|
||||
el.text = six.text_type(obj)
|
||||
elif type(obj) in (datetime.date, datetime.time, datetime.datetime):
|
||||
el.text = obj.isoformat()
|
||||
@ -98,6 +98,8 @@ def loadxml(el, datatype):
|
||||
return parse_isotime(el.text)
|
||||
if datatype == datetime.datetime:
|
||||
return parse_isodatetime(el.text)
|
||||
if datatype == bool:
|
||||
return el.text.lower() != 'false'
|
||||
if datatype is None:
|
||||
return el.text
|
||||
if datatype is wsme.types.bytes:
|
||||
|
@ -18,7 +18,7 @@ class TestSpore(unittest.TestCase):
|
||||
|
||||
spore = json.loads(spore)
|
||||
|
||||
assert len(spore['methods']) == 43, str(len(spore['methods']))
|
||||
assert len(spore['methods']) == 45, str(len(spore['methods']))
|
||||
|
||||
m = spore['methods']['argtypes_setbytesarray']
|
||||
assert m['path'] == 'argtypes/setbytesarray', m['path']
|
||||
|
Loading…
x
Reference in New Issue
Block a user