summaryrefslogtreecommitdiffstats
path: root/ipalib/tests
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-07-22 06:41:33 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-07-22 06:41:33 +0000
commitfc33f5d359573cd977d168ea1fbed97cdc55c992 (patch)
tree6532ceb40e602993a4aab8e2fa80423968aeaafe /ipalib/tests
parent0c574d830062d7957c2c65081e3e66fc0bb41759 (diff)
downloadfreeipa.git-fc33f5d359573cd977d168ea1fbed97cdc55c992.tar.gz
freeipa.git-fc33f5d359573cd977d168ea1fbed97cdc55c992.tar.xz
freeipa.git-fc33f5d359573cd977d168ea1fbed97cdc55c992.zip
28: Added new base.Register class that is a more generic way of doing the plugin registration and doesn't itself instatiate any plugins; added corresponding unit tests
Diffstat (limited to 'ipalib/tests')
-rw-r--r--ipalib/tests/test_base.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/ipalib/tests/test_base.py b/ipalib/tests/test_base.py
index 7affd997..f11f1f4f 100644
--- a/ipalib/tests/test_base.py
+++ b/ipalib/tests/test_base.py
@@ -347,3 +347,64 @@ def test_Registar():
assert len(r.commands) == 3
assert list(r.commands) == sorted(['kinit', 'add_user', 'del_user'])
+
+
+class test_Register():
+ r = base.Register()
+
+ assert set(r) == set(['Command', 'Object', 'Method', 'Property'])
+
+
+ class wrong_base(object):
+ pass
+
+ class krbtest(base.Command):
+ pass
+
+ class user(base.Object):
+ pass
+
+ class user__add(base.Method):
+ pass
+
+ class user__firstname(base.Property):
+ pass
+
+
+
+
+ #r(wrong_base)
+ #r(user())
+
+ # Check that exception is raised trying to register an instance of a
+ # class of a correct base:
+ raised = False
+ try:
+ r(user())
+ except exceptions.RegistrationError:
+ raised = True
+
+ # Check that exception is raised trying to register class of wrong base:
+ raised = False
+ try:
+ r(wrong_base)
+ except exceptions.RegistrationError:
+ raised = True
+ assert raised
+
+ # Check that added a valid class works
+ for cls in (krbtest, user, user__add, user__firstname):
+ r(cls)
+ key = cls.__bases__[0].__name__
+ d = r[key]
+ assert d.keys() == [cls.__name__]
+ assert d.values() == [cls]
+ # Check that a copy is returned
+ d2 = r[key]
+ assert d2 == d
+ assert d2 is not d
+ p = getattr(r, key)
+ assert isinstance(p, base.Proxy)
+ # Check that same instance is returned
+ assert p is getattr(r, key)
+ assert getattr(p, cls.__name__) is cls