diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 9025c1db6..f298e97e8 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 fc7fff982..a6f1e7cdc 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)