summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-03 17:27:53 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-01-03 17:27:53 -0700
commit6b6e6b1cab7a633faf16631a565ecb6988dadb48 (patch)
tree86b5b24485955ac3186beb7e350b77c47fefa5b3 /tests
parentd1517b95ca14773773647434fb589c8224307328 (diff)
downloadfreeipa-6b6e6b1cab7a633faf16631a565ecb6988dadb48.tar.gz
freeipa-6b6e6b1cab7a633faf16631a565ecb6988dadb48.tar.xz
freeipa-6b6e6b1cab7a633faf16631a565ecb6988dadb48.zip
Ported plugin registration errors into errors2.py; plugable.Registrar now raises new errors2 exceptions
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipalib/test_error2.py78
-rw-r--r--tests/test_ipalib/test_plugable.py22
2 files changed, 93 insertions, 7 deletions
diff --git a/tests/test_ipalib/test_error2.py b/tests/test_ipalib/test_error2.py
index f8b1a314d..9be247561 100644
--- a/tests/test_ipalib/test_error2.py
+++ b/tests/test_ipalib/test_error2.py
@@ -92,16 +92,92 @@ class test_SubprocessError(PrivateExceptionTester):
"""
Test the `ipalib.errors2.SubprocessError` exception.
"""
+
_klass = errors2.SubprocessError
def test_init(self):
"""
Test the `ipalib.errors2.SubprocessError.__init__` method.
"""
- inst = self.klass(returncode=1, argv=('/bin/false',))
+ inst = self.new(returncode=1, argv=('/bin/false',))
assert inst.returncode == 1
assert inst.argv == ('/bin/false',)
assert str(inst) == "return code 1 from ('/bin/false',)"
+ assert inst.message == str(inst)
+
+
+class test_PluginSubclassError(PrivateExceptionTester):
+ """
+ Test the `ipalib.errors2.PluginSubclassError` exception.
+ """
+
+ _klass = errors2.PluginSubclassError
+
+ def test_init(self):
+ """
+ Test the `ipalib.errors2.PluginSubclassError.__init__` method.
+ """
+ inst = self.new(plugin='bad', bases=('base1', 'base2'))
+ assert inst.plugin == 'bad'
+ assert inst.bases == ('base1', 'base2')
+ assert str(inst) == \
+ "'bad' not subclass of any base in ('base1', 'base2')"
+ assert inst.message == str(inst)
+
+
+class test_PluginDuplicateError(PrivateExceptionTester):
+ """
+ Test the `ipalib.errors2.PluginDuplicateError` exception.
+ """
+
+ _klass = errors2.PluginDuplicateError
+
+ def test_init(self):
+ """
+ Test the `ipalib.errors2.PluginDuplicateError.__init__` method.
+ """
+ inst = self.new(plugin='my_plugin')
+ assert inst.plugin == 'my_plugin'
+ assert str(inst) == "'my_plugin' was already registered"
+ assert inst.message == str(inst)
+
+
+class test_PluginOverrideError(PrivateExceptionTester):
+ """
+ Test the `ipalib.errors2.PluginOverrideError` exception.
+ """
+
+ _klass = errors2.PluginOverrideError
+
+ def test_init(self):
+ """
+ Test the `ipalib.errors2.PluginOverrideError.__init__` method.
+ """
+ inst = self.new(base='Base', name='cmd', plugin='my_cmd')
+ assert inst.base == 'Base'
+ assert inst.name == 'cmd'
+ assert inst.plugin == 'my_cmd'
+ assert str(inst) == "unexpected override of Base.cmd with 'my_cmd'"
+ assert inst.message == str(inst)
+
+
+class test_PluginMissingOverrideError(PrivateExceptionTester):
+ """
+ Test the `ipalib.errors2.PluginMissingOverrideError` exception.
+ """
+
+ _klass = errors2.PluginMissingOverrideError
+
+ def test_init(self):
+ """
+ Test the `ipalib.errors2.PluginMissingOverrideError.__init__` method.
+ """
+ inst = self.new(base='Base', name='cmd', plugin='my_cmd')
+ assert inst.base == 'Base'
+ assert inst.name == 'cmd'
+ assert inst.plugin == 'my_cmd'
+ assert str(inst) == "Base.cmd not registered, cannot override with 'my_cmd'"
+ assert inst.message == str(inst)
def test_public_errors():
diff --git a/tests/test_ipalib/test_plugable.py b/tests/test_ipalib/test_plugable.py
index 9eb102ff4..dbf0cc3ff 100644
--- a/tests/test_ipalib/test_plugable.py
+++ b/tests/test_ipalib/test_plugable.py
@@ -25,7 +25,7 @@ import inspect
from tests.util import raises, no_set, no_del, read_only
from tests.util import getitem, setitem, delitem
from tests.util import ClassChecker, create_test_api
-from ipalib import plugable, errors
+from ipalib import plugable, errors, errors2
class test_SetProxy(ClassChecker):
@@ -534,11 +534,14 @@ def test_Registrar():
# Check that TypeError is raised trying to register something that isn't
# a class:
- raises(TypeError, r, plugin1())
+ p = plugin1()
+ e = raises(TypeError, r, p)
+ assert str(e) == 'plugin must be a class; got %r' % p
# Check that SubclassError is raised trying to register a class that is
# not a subclass of an allowed base:
- raises(errors.SubclassError, r, plugin3)
+ e = raises(errors2.PluginSubclassError, r, plugin3)
+ assert e.plugin is plugin3
# Check that registration works
r(plugin1)
@@ -548,7 +551,8 @@ def test_Registrar():
# Check that DuplicateError is raised trying to register exact class
# again:
- raises(errors.DuplicateError, r, plugin1)
+ e = raises(errors2.PluginDuplicateError, r, plugin1)
+ assert e.plugin is plugin1
# Check that OverrideError is raised trying to register class with same
# name and same base:
@@ -557,7 +561,10 @@ def test_Registrar():
pass
class plugin1(base1_extended):
pass
- raises(errors.OverrideError, r, plugin1)
+ e = raises(errors2.PluginOverrideError, r, plugin1)
+ assert e.base == 'Base1'
+ assert e.name == 'plugin1'
+ assert e.plugin is plugin1
# Check that overriding works
r(plugin1, override=True)
@@ -567,7 +574,10 @@ def test_Registrar():
# Check that MissingOverrideError is raised trying to override a name
# not yet registerd:
- raises(errors.MissingOverrideError, r, plugin2, override=True)
+ e = raises(errors2.PluginMissingOverrideError, r, plugin2, override=True)
+ assert e.base == 'Base2'
+ assert e.name == 'plugin2'
+ assert e.plugin is plugin2
# Test that another plugin can be registered:
assert len(r.Base2) == 0