Print exceptions raised from from_param methods

This makes debugging the problems easier.

Change-Id: I285d8176b8cfb0cdf1e9cecd8ae5a0a7f0f109e7
This commit is contained in:
Vladyslav Drok 2016-12-22 14:32:01 +02:00
parent ecaf3aa40f
commit 1670793bfe
3 changed files with 30 additions and 3 deletions

View File

@ -91,7 +91,8 @@ class TestWS(FunctionalTest):
self.assertEqual(
a['faultstring'],
"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):
expected_status_code = 400

View File

@ -178,7 +178,7 @@ def args_from_args(funcdef, args, kwargs):
for argdef, arg in zip(funcdef.arguments[:len(args)], args):
try:
newargs.append(from_param(argdef.datatype, arg))
except Exception:
except Exception as e:
if isinstance(argdef.datatype, UserType):
datatype_name = argdef.datatype.name
elif isinstance(argdef.datatype, type):
@ -188,7 +188,8 @@ def args_from_args(funcdef, args, kwargs):
raise InvalidInput(
argdef.name,
arg,
"unable to convert to %s" % datatype_name)
"unable to convert to %(datatype)s. Error: %(error)s" % {
'datatype': datatype_name, 'error': e})
newkwargs = {}
for argname, value in kwargs.items():
newkwargs[argname] = from_param(

View File

@ -93,6 +93,31 @@ class TestProtocolsCommons(unittest.TestCase):
else:
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):
fake_type = ArrayType(MyBaseType)
fd = FunctionDefinition(FunctionDefinition)