summaryrefslogtreecommitdiffstats
path: root/ipatests/test_xmlrpc/xmlrpc_test.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2014-12-10 14:43:57 +0100
committerTomas Babej <tbabej@redhat.com>2015-01-14 11:40:28 +0100
commit4d9112b5c694f032f7d2711d1cd050dfde302e80 (patch)
treee6e2be19d03a4bd6e6cd6b6a2300313ead5f15ce /ipatests/test_xmlrpc/xmlrpc_test.py
parent61c4ecccc1df222b153236518c9be0ac3091f94a (diff)
downloadfreeipa-4d9112b5c694f032f7d2711d1cd050dfde302e80.tar.gz
freeipa-4d9112b5c694f032f7d2711d1cd050dfde302e80.tar.xz
freeipa-4d9112b5c694f032f7d2711d1cd050dfde302e80.zip
test_host_plugin: Convert tests to imperative style
This has several advantages: - Tests other than run-command/check-response can be added easily - Tracebacks are meaningful (which means we'll be able to remove a lot of test name/description/location tracking code) - Individual tests can be selected/deselected using normal pytest mechanisms (but for isolated tests, more changes will be needed) Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipatests/test_xmlrpc/xmlrpc_test.py')
-rw-r--r--ipatests/test_xmlrpc/xmlrpc_test.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/ipatests/test_xmlrpc/xmlrpc_test.py b/ipatests/test_xmlrpc/xmlrpc_test.py
index 03c5b5bd6..acfdf711d 100644
--- a/ipatests/test_xmlrpc/xmlrpc_test.py
+++ b/ipatests/test_xmlrpc/xmlrpc_test.py
@@ -22,7 +22,10 @@ Base class for all XML-RPC tests
"""
import datetime
+
import nose
+import contextlib
+
from ipatests.util import assert_deepequal, Fuzzy
from ipalib import api, request, errors
from ipalib.x509 import valid_issuer
@@ -225,6 +228,9 @@ KWARGS = """Command %r raised %s with wrong kwargs.
class Declarative(XMLRPC_test):
"""A declarative-style test suite
+ This class is DEPRECATED. Use RPCTest instead.
+ See host plugin tests for an example.
+
A Declarative test suite is controlled by the ``tests`` and
``cleanup_commands`` class variables.
@@ -341,3 +347,52 @@ class Declarative(XMLRPC_test):
assert_deepequal(expected, got, nice)
if extra_check and not extra_check(got):
raise AssertionError('Extra check %s failed' % extra_check)
+
+
+@contextlib.contextmanager
+def raises_exact(expected_exception):
+ """Check that a specific PublicError is raised
+
+ Both type and message of the error are checked.
+
+ >>> with raises_exact(errors.ValidationError(name='x', error='y')):
+ ... raise errors.ValidationError(name='x', error='y')
+ """
+ try:
+ yield
+ except errors.PublicError as got_exception:
+ assert type(expected_exception) is type(got_exception)
+ # FIXME: We should return error information in a structured way.
+ # For now just compare the strings
+ assert expected_exception.strerror == got_exception.strerror
+ else:
+ raise AssertionError('did not raise!')
+
+
+class RPCTest(XMLRPC_test):
+ """Base class for RPC tests"""
+ @classmethod
+ def setup_class(cls):
+ super(RPCTest, cls).setup_class()
+ cls.clean_up()
+
+ @classmethod
+ def teardown_class(cls):
+ cls.clean_up()
+ super(RPCTest, cls).teardown_class()
+
+ @classmethod
+ def clean_up(self):
+ """Cleanup run on both setup and teardown
+
+ To be overridden in subclasses.
+ Usually calls the clean() method.
+ """
+
+ @classmethod
+ def clean(cls, command, *args, **options):
+ """Run a command, ignoring NotFound/EmptyModlist errors"""
+ try:
+ api.Command[command](*args, **options)
+ except (errors.NotFound, errors.EmptyModlist):
+ pass