Fixes exception path with the datatype is a Object

If the object type is ArrayType or DictType, the datatype
is an object not a class. Currently a 500 error is raise
just because the exception path for invalid input handle only
when the datatype is an UserType or Class, not object.

This change fixes that.

Change-Id: Ifadef698a4dca0d33167bd4d5a567c43fe015108
Closes-bug: #1428185
This commit is contained in:
Mehdi Abaakouk 2015-08-03 14:30:31 +02:00
parent 1526b4ce62
commit 2cb266eadb
2 changed files with 19 additions and 2 deletions

View File

@ -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,

View File

@ -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):