summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-01 21:25:46 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-01 21:25:46 +0000
commit74f5719078adfcfdf8b98bf97f0828dd150c840d (patch)
treed5ce275251f93b1a72df10e6494820276053326e /ipalib
parenta0f480a414d2aa3a5f79e77026ff9183c1dd3a48 (diff)
downloadfreeipa.git-74f5719078adfcfdf8b98bf97f0828dd150c840d.tar.gz
freeipa.git-74f5719078adfcfdf8b98bf97f0828dd150c840d.tar.xz
freeipa.git-74f5719078adfcfdf8b98bf97f0828dd150c840d.zip
42: plugable.Plugin.__init__() now takes the plugable.API instance as its single argument
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugable.py19
-rw-r--r--ipalib/tests/test_plugable.py15
2 files changed, 29 insertions, 5 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 9025c1db..f298e97e 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -49,6 +49,16 @@ class Plugin(object):
Base class for all plugins.
"""
+ def __init__(self, api):
+ self.__api = api
+
+ def __get_api(self):
+ """
+ Returns the plugable.API object this plugin has been instatiated in.
+ """
+ return self.__api
+ api = property(__get_api)
+
def __get_name(self):
"""
Returns the class name of this instance.
@@ -132,6 +142,8 @@ class NameSpace(ReadOnly):
def __init__(self, items):
"""
+ `items` should be an iterable providing the members of this
+ NameSpace.
"""
object.__setattr__(self, '_NameSpace__items', tuple(items))
@@ -182,7 +194,6 @@ class NameSpace(ReadOnly):
raise KeyError('NameSpace has no item for key %r' % key)
-
class Registrar(object):
def __init__(self, *allowed):
"""
@@ -265,3 +276,9 @@ class Registrar(object):
"""
for base in self.__allowed:
yield (base, self.__d[base.__name__].values())
+
+
+class API(ReadOnly):
+ def __init__(self, registrar):
+ for (base, plugins) in registrar:
+ pass
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py
index fc7fff98..a6f1e7cd 100644
--- a/ipalib/tests/test_plugable.py
+++ b/ipalib/tests/test_plugable.py
@@ -42,14 +42,17 @@ def test_from_cli():
def test_Plugin():
- p = plugable.Plugin()
- assert p.name == 'Plugin'
+ api = 'the api instance'
+ p = plugable.Plugin(api)
+ assert read_only(p, 'api') is api
+ assert read_only(p, 'name') == 'Plugin'
assert repr(p) == '%s.Plugin()' % plugable.__name__
class some_plugin(plugable.Plugin):
pass
- p = some_plugin()
- assert p.name == 'some_plugin'
+ p = some_plugin(api)
+ assert read_only(p, 'api') is api
+ assert read_only(p, 'name') == 'some_plugin'
assert repr(p) == '%s.some_plugin()' % __name__
@@ -302,3 +305,7 @@ def test_NameSpace():
raises(KeyError, getitem, ns, cli)
raises(AttributeError, getattr, ns, name)
no_set(ns, name)
+
+
+def test_API():
+ assert issubclass(plugable.API, plugable.ReadOnly)