Print exceptions raised from from_param methods
This makes debugging the problems easier. Change-Id: I285d8176b8cfb0cdf1e9cecd8ae5a0a7f0f109e7
This commit is contained in:
parent
ecaf3aa40f
commit
1670793bfe
@ -91,7 +91,8 @@ class TestWS(FunctionalTest):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
a['faultstring'],
|
a['faultstring'],
|
||||||
"Invalid input for field/attribute author_id. "
|
"Invalid input for field/attribute author_id. "
|
||||||
"Value: 'foobar'. unable to convert to int")
|
"Value: 'foobar'. unable to convert to int. Error: invalid "
|
||||||
|
"literal for int() with base 10: 'foobar'")
|
||||||
|
|
||||||
def test_clientsideerror(self):
|
def test_clientsideerror(self):
|
||||||
expected_status_code = 400
|
expected_status_code = 400
|
||||||
|
@ -178,7 +178,7 @@ def args_from_args(funcdef, args, kwargs):
|
|||||||
for argdef, arg in zip(funcdef.arguments[:len(args)], args):
|
for argdef, arg in zip(funcdef.arguments[:len(args)], args):
|
||||||
try:
|
try:
|
||||||
newargs.append(from_param(argdef.datatype, arg))
|
newargs.append(from_param(argdef.datatype, arg))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
if isinstance(argdef.datatype, UserType):
|
if isinstance(argdef.datatype, UserType):
|
||||||
datatype_name = argdef.datatype.name
|
datatype_name = argdef.datatype.name
|
||||||
elif isinstance(argdef.datatype, type):
|
elif isinstance(argdef.datatype, type):
|
||||||
@ -188,7 +188,8 @@ def args_from_args(funcdef, args, kwargs):
|
|||||||
raise InvalidInput(
|
raise InvalidInput(
|
||||||
argdef.name,
|
argdef.name,
|
||||||
arg,
|
arg,
|
||||||
"unable to convert to %s" % datatype_name)
|
"unable to convert to %(datatype)s. Error: %(error)s" % {
|
||||||
|
'datatype': datatype_name, 'error': e})
|
||||||
newkwargs = {}
|
newkwargs = {}
|
||||||
for argname, value in kwargs.items():
|
for argname, value in kwargs.items():
|
||||||
newkwargs[argname] = from_param(
|
newkwargs[argname] = from_param(
|
||||||
|
@ -93,6 +93,31 @@ class TestProtocolsCommons(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.fail('Should have thrown an InvalidInput')
|
self.fail('Should have thrown an InvalidInput')
|
||||||
|
|
||||||
|
def test_args_from_args_custom_exc(self):
|
||||||
|
|
||||||
|
class FakeType(UserType):
|
||||||
|
name = 'fake-type'
|
||||||
|
basetype = int
|
||||||
|
|
||||||
|
def validate(self, value):
|
||||||
|
if value < 10:
|
||||||
|
raise ValueError('should be greater than 10')
|
||||||
|
|
||||||
|
def frombasetype(self, value):
|
||||||
|
self.validate(value)
|
||||||
|
|
||||||
|
fake_type = FakeType()
|
||||||
|
fd = FunctionDefinition(FunctionDefinition)
|
||||||
|
fd.arguments.append(FunctionArgument('fake-arg', fake_type, True, 0))
|
||||||
|
|
||||||
|
try:
|
||||||
|
args_from_args(fd, [9], {})
|
||||||
|
except InvalidInput as e:
|
||||||
|
assert fake_type.name in str(e)
|
||||||
|
assert 'Error: should be greater than 10' in str(e)
|
||||||
|
else:
|
||||||
|
self.fail('Should have thrown an InvalidInput')
|
||||||
|
|
||||||
def test_args_from_args_array_type(self):
|
def test_args_from_args_array_type(self):
|
||||||
fake_type = ArrayType(MyBaseType)
|
fake_type = ArrayType(MyBaseType)
|
||||||
fd = FunctionDefinition(FunctionDefinition)
|
fd = FunctionDefinition(FunctionDefinition)
|
||||||
|
Loading…
Reference in New Issue
Block a user