diff --git a/wsme/rest/args.py b/wsme/rest/args.py index 80613e2..55fb4eb 100644 --- a/wsme/rest/args.py +++ b/wsme/rest/args.py @@ -181,8 +181,10 @@ def args_from_args(funcdef, args, kwargs): except Exception: if isinstance(argdef.datatype, UserType): datatype_name = argdef.datatype.name - else: + elif isinstance(argdef.datatype, type): datatype_name = argdef.datatype.__name__ + else: + datatype_name = argdef.datatype.__class__.__name__ raise InvalidInput( argdef.name, arg, diff --git a/wsme/tests/test_protocols_commons.py b/wsme/tests/test_protocols_commons.py index 5cb0268..6d99c45 100644 --- a/wsme/tests/test_protocols_commons.py +++ b/wsme/tests/test_protocols_commons.py @@ -7,7 +7,11 @@ from wsme.api import FunctionArgument, FunctionDefinition from wsme.rest.args import from_param, from_params, args_from_args from wsme.exc import InvalidInput -from wsme.types import UserType, Unset, ArrayType, DictType +from wsme.types import UserType, Unset, ArrayType, DictType, Base + + +class MyBaseType(Base): + test = str class MyUserType(UserType): @@ -89,6 +93,17 @@ class TestProtocolsCommons(unittest.TestCase): else: self.fail('Should have thrown an InvalidInput') + def test_args_from_args_array_type(self): + fake_type = ArrayType(MyBaseType) + fd = FunctionDefinition(FunctionDefinition) + fd.arguments.append(FunctionArgument('fake-arg', fake_type, True, [])) + try: + args_from_args(fd, [['invalid-argument']], {}) + except InvalidInput as e: + assert ArrayType.__name__ in str(e) + else: + self.fail('Should have thrown an InvalidInput') + class ArgTypeConversion(unittest.TestCase):