summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-21 21:30:19 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-21 21:30:19 +0000
commit5872221bd49dda962391ddfb88f22e86bf72afec (patch)
tree11b4430cf5a22b1788b144adbac75daf4b079d4c
parent2d836140064154c461aec1b24ae8d774cbd12444 (diff)
downloadfreeipa-5872221bd49dda962391ddfb88f22e86bf72afec.tar.gz
freeipa-5872221bd49dda962391ddfb88f22e86bf72afec.tar.xz
freeipa-5872221bd49dda962391ddfb88f22e86bf72afec.zip
306: Added Plugin.set_api() method; added corresponding unit tests
-rw-r--r--ipalib/plugable.py8
-rw-r--r--ipalib/tests/test_plugable.py14
2 files changed, 22 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 9db4a5c6..19eae504 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -352,6 +352,14 @@ class Plugin(ReadOnly):
assert api is not None, 'finalize() argument cannot be None'
self.__api = api
+ def set_api(self, api):
+ """
+ Set reference to `API` instance.
+ """
+ assert self.__api is None, 'set_api() can only be called once'
+ assert api is not None, 'set_api() argument cannot be None'
+ self.__api = api
+
def __repr__(self):
"""
Returns a fully qualified module_name.class_name() representation that
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py
index 9623f99e..3972cfa9 100644
--- a/ipalib/tests/test_plugable.py
+++ b/ipalib/tests/test_plugable.py
@@ -387,6 +387,20 @@ class test_Plugin(ClassChecker):
assert base.implemented_by(fail) is False
assert base.implemented_by(fail()) is False
+ def test_set_api(self):
+ """
+ Tests the `plugable.Plugin.set_api` method.
+ """
+ api = 'the api instance'
+ o = self.cls()
+ assert o.api is None
+ e = raises(AssertionError, o.set_api, None)
+ assert str(e) == 'set_api() argument cannot be None'
+ o.set_api(api)
+ assert o.api is api
+ e = raises(AssertionError, o.set_api, api)
+ assert str(e) == 'set_api() can only be called once'
+
def test_finalize(self):
"""
Tests the `plugable.Plugin.finalize` method.