summaryrefslogtreecommitdiffstats
path: root/tests
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
parent1d6e23136a0664a86b765c67a9308f0951652f74 (diff)
downloadfreeipa-f58ff2921defef330d53e08e427a82ced7585c88.tar.gz
freeipa-f58ff2921defef330d53e08e427a82ced7585c88.tar.xz
freeipa-f58ff2921defef330d53e08e427a82ced7585c88.zip
Giant webui patch take 2
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipalib/test_parameters.py21
-rw-r--r--tests/test_ipaserver/test_rpcserver.py63
-rw-r--r--tests/test_ipawebui/test_controllers.py52
3 files changed, 87 insertions, 49 deletions
diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py
index d651b2366..f43fa3227 100644
--- a/tests/test_ipalib/test_parameters.py
+++ b/tests/test_ipalib/test_parameters.py
@@ -60,6 +60,27 @@ class test_DefaultFrom(ClassChecker):
e = raises(TypeError, self.cls, callback, 'givenname', 17)
assert str(e) == TYPE_ERROR % ('keys', str, 17, int)
+ def test_repr(self):
+ """
+ Test the `ipalib.parameters.DefaultFrom.__repr__` method.
+ """
+ def stuff(one, two):
+ pass
+
+ o = self.cls(stuff)
+ assert repr(o) == "DefaultFrom(stuff, 'one', 'two')"
+
+ o = self.cls(stuff, 'aye', 'bee', 'see')
+ assert repr(o) == "DefaultFrom(stuff, 'aye', 'bee', 'see')"
+
+ cb = lambda first, last: first[0] + last
+
+ o = self.cls(cb)
+ assert repr(o) == "DefaultFrom(<lambda>, 'first', 'last')"
+
+ o = self.cls(cb, 'aye', 'bee', 'see')
+ assert repr(o) == "DefaultFrom(<lambda>, 'aye', 'bee', 'see')"
+
def test_call(self):
"""
Test the `ipalib.parameters.DefaultFrom.__call__` method.
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)
diff --git a/tests/test_ipawebui/test_controllers.py b/tests/test_ipawebui/test_controllers.py
index e236d1a0b..a08319b40 100644
--- a/tests/test_ipawebui/test_controllers.py
+++ b/tests/test_ipawebui/test_controllers.py
@@ -17,54 +17,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-Test the `ipawebui.controller` module.
+Test the `ipawebui.controllers` module.
"""
-from ipawebui import controller
-
-
-
-class test_Controller(object):
- """
- Test the `controller.Controller` class.
- """
-
- def test_init(self):
- """
- Test the `ipawebui.controller.Controller.__init__()` method.
- """
- o = controller.Controller()
- assert o.template is None
- template = 'The template.'
- o = controller.Controller(template)
- assert o.template is template
-
- def test_output_xhtml(self):
- """
- Test the `ipawebui.controller.Controller.output_xhtml` method.
- """
- class Template(object):
- def __init__(self):
- self.calls = 0
- self.kw = {}
-
- def serialize(self, **kw):
- self.calls += 1
- self.kw = kw
- return dict(kw)
-
- d = dict(output='xhtml-strict', format='pretty')
- t = Template()
- o = controller.Controller(t)
- assert o.output_xhtml() == d
- assert t.calls == 1
-
- def test_output_json(self):
- """
- Test the `ipawebui.controller.Controller.output_json` method.
- """
- o = controller.Controller()
- assert o.output_json() == '{}'
- e = '{\n "age": 27, \n "first": "John", \n "last": "Doe"\n}'
- j = o.output_json(last='Doe', first='John', age=27)
- assert j == e
+from wsgiref import util
+from wsgiref.validate import validator