summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdi Abaakouk <sileht@sileht.net>2015-08-03 14:30:31 +0200
committerMehdi Abaakouk <sileht@sileht.net>2015-08-03 16:06:09 +0200
commit2cb266eadb8a0147328433ea85370cb68cf30e6f (patch)
tree546757f3268d0a392135dcd0942f9c4b41a309ab
parent1526b4ce62a1f1ee5d007201db4c190148dda6a4 (diff)
downloadwsme-2cb266eadb8a0147328433ea85370cb68cf30e6f.tar.gz
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
-rw-r--r--wsme/rest/args.py4
-rw-r--r--wsme/tests/test_protocols_commons.py17
2 files changed, 19 insertions, 2 deletions
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):