summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-11-24 21:34:01 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-11-24 21:34:01 -0700
commit2d458a12339fbb7ef006ff7defc1e2f541e2f23f (patch)
tree04f1b19fe0763c1d0d5671dfee8c328dcd9cd002 /tests
parent237c16f0fd3998f4a2e69d9096997d10af2cf8c9 (diff)
downloadfreeipa-2d458a12339fbb7ef006ff7defc1e2f541e2f23f.tar.gz
freeipa-2d458a12339fbb7ef006ff7defc1e2f541e2f23f.tar.xz
freeipa-2d458a12339fbb7ef006ff7defc1e2f541e2f23f.zip
Stared some RPC-related error cleanup; started work on ipa_server.rcp.xmlrpc plugin
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipa_server/test_rpc.py43
-rw-r--r--tests/test_ipalib/test_rpc.py6
-rw-r--r--tests/util.py57
3 files changed, 103 insertions, 3 deletions
diff --git a/tests/test_ipa_server/test_rpc.py b/tests/test_ipa_server/test_rpc.py
new file mode 100644
index 00000000..56ad3f06
--- /dev/null
+++ b/tests/test_ipa_server/test_rpc.py
@@ -0,0 +1,43 @@
+# Authors:
+# Jason Gerard DeRose <jderose@redhat.com>
+#
+# Copyright (C) 2008 Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2 only
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""
+Test the `ipa_server.rpc` module.
+"""
+
+from tests.util import create_test_api, raises, PluginTester
+from ipalib import errors, Command
+from ipa_server import rpc
+
+
+class test_xmlrpc(PluginTester):
+ """
+ Test the `ipa_server.rpc.xmlrpc` plugin.
+ """
+
+ _plugin = rpc.xmlrpc
+
+ def test_dispatch(self):
+ """
+ Test the `ipa_server.rpc.xmlrpc.dispatch` method.
+ """
+ (o, api, home) = self.instance('Backend')
+ e = raises(errors.CommandError, o.dispatch, 'example', tuple())
+ assert str(e) == "Unknown command 'example'"
+ assert e.kw['name'] == 'example'
diff --git a/tests/test_ipalib/test_rpc.py b/tests/test_ipalib/test_rpc.py
index 14af2bf4..e8d73931 100644
--- a/tests/test_ipalib/test_rpc.py
+++ b/tests/test_ipalib/test_rpc.py
@@ -32,10 +32,10 @@ BINARY_BYTES = ''.join(struct.pack('B', d) for d in xrange(256))
assert '\x00' in BINARY_BYTES and '\xff' in BINARY_BYTES
assert type(BINARY_BYTES) is str and len(BINARY_BYTES) == 256
-# A UTF-8 encoded str
+# A UTF-8 encoded str:
UTF8_BYTES = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb'
-# The same UTF-8 data decoded (a unicode instance)
+# The same UTF-8 data decoded (a unicode instance):
UNICODE_CHARS = u'\u041f\u0430\u0432\u0435\u043b'
assert UTF8_BYTES.decode('UTF-8') == UNICODE_CHARS
assert UNICODE_CHARS.encode('UTF-8') == UTF8_BYTES
@@ -60,7 +60,7 @@ def test_round_trip():
Test `ipalib.rpc.xmlrpc_wrap` and `ipalib.rpc.xmlrpc_unwrap`.
This tests the two functions together with ``xmlrpclib.dumps()`` and
- ``xmlrpclib.loads()`` in a full encode/dumps/loads/decode round trip.
+ ``xmlrpclib.loads()`` in a full wrap/dumps/loads/unwrap round trip.
"""
# We first test that our assumptions about xmlrpclib module in the Python
# standard library are correct:
diff --git a/tests/util.py b/tests/util.py
index 0efca5d4..22b8a770 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -27,6 +27,7 @@ from os import path
import tempfile
import shutil
import ipalib
+from ipalib.plugable import Plugin
@@ -198,6 +199,11 @@ class ClassChecker(object):
)
+
+
+
+
+
def check_TypeError(value, type_, name, callback, *args, **kw):
"""
Tests a standard TypeError raised with `errors.raise_TypeError`.
@@ -224,3 +230,54 @@ def get_api(**kw):
for (key, value) in kw.iteritems():
api.env[key] = value
return (api, home)
+
+
+def create_test_api(**kw):
+ """
+ Returns (api, home) tuple.
+
+ This function returns a tuple containing an `ipalib.plugable.API`
+ instance and a `TempHome` instance.
+ """
+ home = TempHome()
+ api = ipalib.create_api(mode='unit_test')
+ api.env.in_tree = True
+ for (key, value) in kw.iteritems():
+ api.env[key] = value
+ return (api, home)
+
+
+class PluginTester(object):
+ __plugin = None
+
+ def __get_plugin(self):
+ if self.__plugin is None:
+ self.__plugin = self._plugin
+ assert issubclass(self.__plugin, Plugin)
+ return self.__plugin
+ plugin = property(__get_plugin)
+
+ def register(self, *plugins, **kw):
+ """
+ Create a testing api and register ``self.plugin``.
+
+ This method returns an (api, home) tuple.
+
+ :param plugins: Additional \*plugins to register.
+ :param kw: Additional \**kw args to pass to `create_test_api`.
+ """
+ (api, home) = create_test_api(**kw)
+ api.register(self.plugin)
+ for p in plugins:
+ api.register(p)
+ return (api, home)
+
+ def finalize(self, *plugins, **kw):
+ (api, home) = self.register(*plugins, **kw)
+ api.finalize()
+ return (api, home)
+
+ def instance(self, namespace, *plugins, **kw):
+ (api, home) = self.finalize(*plugins, **kw)
+ o = api[namespace][self.plugin.__name__]
+ return (o, api, home)