summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe de Vienne <cdevienne@gmail.com>2014-11-13 21:05:56 +0100
committerChristophe de Vienne <cdevienne@gmail.com>2014-11-15 21:47:25 +0100
commit2bb9362a455755fe69e9859df81155304cf41148 (patch)
treec995ea0563734a8e7c8d3d37867ecf05c129db99
parentea9f71d5f239b2e042d51cc1943afab864e107f5 (diff)
downloadwsme-0.6.2.tar.gz
Fix passing Dict/Array based UserType as params0.6.2
Change-Id: I732c1c292a63a1ec4e6cf341c8268dfe4a600e06
-rw-r--r--doc/changes.rst1
-rw-r--r--wsme/rest/args.py8
-rw-r--r--wsme/tests/test_protocols_commons.py13
3 files changed, 22 insertions, 0 deletions
diff --git a/doc/changes.rst b/doc/changes.rst
index 98b93f6..0a85801 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -8,6 +8,7 @@ Changes
* Allow disabling complex types auto-register
* Documentation edits
* Various documentation build fixes
+* Fix passing Dict and Array based UserType as params
0.6.1 (2014-05-02)
------------------
diff --git a/wsme/rest/args.py b/wsme/rest/args.py
index 0c4f6cf..0c6e1c6 100644
--- a/wsme/rest/args.py
+++ b/wsme/rest/args.py
@@ -165,6 +165,14 @@ def dict_from_params(datatype, params, path, hit_paths):
for key in keys))
+@from_params.when_type(UserType)
+def usertype_from_params(datatype, params, path, hit_paths):
+ value = from_params(datatype.basetype, params, path, hit_paths)
+ if value is not Unset:
+ return datatype.frombasetype(value)
+ return Unset
+
+
def args_from_args(funcdef, args, kwargs):
newargs = []
for argdef, arg in zip(funcdef.arguments[:len(args)], args):
diff --git a/wsme/tests/test_protocols_commons.py b/wsme/tests/test_protocols_commons.py
index 6a4c1a8..5cb0268 100644
--- a/wsme/tests/test_protocols_commons.py
+++ b/wsme/tests/test_protocols_commons.py
@@ -14,6 +14,10 @@ class MyUserType(UserType):
basetype = str
+class DictBasedUserType(UserType):
+ basetype = DictType(int, int)
+
+
class TestProtocolsCommons(unittest.TestCase):
def test_from_param_date(self):
assert from_param(datetime.date, '2008-02-28') == \
@@ -55,6 +59,15 @@ class TestProtocolsCommons(unittest.TestCase):
def test_from_params_dict_unset(self):
assert from_params(DictType(int, str), {}, 'a', set()) is Unset
+ def test_from_params_usertype(self):
+ value = from_params(
+ DictBasedUserType(),
+ {'a[2]': '2'},
+ 'a',
+ set()
+ )
+ self.assertEqual(value, {2: 2})
+
def test_args_from_args_usertype(self):
class FakeType(UserType):