summaryrefslogtreecommitdiffstats
path: root/tests/test_ipaserver
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-10-13 11:28:00 -0600
committerJason Gerard DeRose <jderose@redhat.com>2009-10-13 11:28:00 -0600
commitf58ff2921defef330d53e08e427a82ced7585c88 (patch)
treec69823174d27be31d4488a331b3fde176f8e2679 /tests/test_ipaserver
parent1d6e23136a0664a86b765c67a9308f0951652f74 (diff)
downloadfreeipa-f58ff2921defef330d53e08e427a82ced7585c88.tar.gz
freeipa-f58ff2921defef330d53e08e427a82ced7585c88.tar.xz
freeipa-f58ff2921defef330d53e08e427a82ced7585c88.zip
Giant webui patch take 2
Diffstat (limited to 'tests/test_ipaserver')
-rw-r--r--tests/test_ipaserver/test_rpcserver.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test_ipaserver/test_rpcserver.py b/tests/test_ipaserver/test_rpcserver.py
index c8cf7e05d..effac4b33 100644
--- a/tests/test_ipaserver/test_rpcserver.py
+++ b/tests/test_ipaserver/test_rpcserver.py
@@ -25,6 +25,7 @@ from tests.util import create_test_api, raises, PluginTester
from tests.data import unicode_str
from ipalib import errors, Command
from ipaserver import rpcserver
+import json
def test_params_2_args_options():
@@ -50,3 +51,65 @@ class test_xmlserver(PluginTester):
def test_marshaled_dispatch(self):
(o, api, home) = self.instance('Backend', in_server=True)
+
+
+class test_jsonserver(PluginTester):
+ """
+ Test the `ipaserver.rpcserver.jsonserver` plugin.
+ """
+
+ _plugin = rpcserver.jsonserver
+
+ def test_unmarshal(self):
+ """
+ Test the `ipaserver.rpcserver.jsonserver.unmarshal` method.
+ """
+ (o, api, home) = self.instance('Backend', in_server=True)
+
+ # Test with invalid JSON-data:
+ e = raises(errors.JSONError, o.unmarshal, 'this wont work')
+ assert isinstance(e.error, ValueError)
+ assert str(e.error) == 'No JSON object could be decoded'
+
+ # Test with non-dict type:
+ e = raises(errors.JSONError, o.unmarshal, json.dumps([1, 2, 3]))
+ assert str(e.error) == 'Request must be a dict'
+
+ params = [[1, 2], dict(three=3, four=4)]
+ # Test with missing method:
+ d = dict(params=params, id=18)
+ e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
+ assert str(e.error) == 'Request is missing "method"'
+
+ # Test with missing params:
+ d = dict(method='echo', id=18)
+ e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
+ assert str(e.error) == 'Request is missing "params"'
+
+ # Test with non-list params:
+ for p in ('hello', dict(args=tuple(), options=dict())):
+ d = dict(method='echo', id=18, params=p)
+ e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
+ assert str(e.error) == 'params must be a list'
+
+ # Test with other than 2 params:
+ for p in ([], [tuple()], [None, dict(), tuple()]):
+ d = dict(method='echo', id=18, params=p)
+ e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
+ assert str(e.error) == 'params must contain [args, options]'
+
+ # Test when args is not a list:
+ d = dict(method='echo', id=18, params=['args', dict()])
+ e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
+ assert str(e.error) == 'params[0] (aka args) must be a list'
+
+ # Test when options is not a dict:
+ d = dict(method='echo', id=18, params=[('hello', 'world'), 'options'])
+ e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
+ assert str(e.error) == 'params[1] (aka options) must be a dict'
+
+ # Test with valid values:
+ args = [u'jdoe']
+ options = dict(givenname=u'John', sn='Doe')
+ d = dict(method=u'user_add', params=[args, options], id=18)
+ assert o.unmarshal(json.dumps(d)) == (u'user_add', args, options, 18)