summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-24 00:44:41 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-24 00:44:41 +0000
commitf3aaf65f1c4bbee31dae9431423ab88a15eba990 (patch)
tree46ddafec983e8337b014e3c9fcda59d7bb6071a3 /ipalib
parent81de10f176437053ac47bfee8f5ec81e38f2cf57 (diff)
downloadfreeipa-f3aaf65f1c4bbee31dae9431423ab88a15eba990.tar.gz
freeipa-f3aaf65f1c4bbee31dae9431423ab88a15eba990.tar.xz
freeipa-f3aaf65f1c4bbee31dae9431423ab88a15eba990.zip
320: plugable.API now respects the Plugin.__proxy__ flag; added test for plugins without proxy to unit tests for API
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/backend.py6
-rw-r--r--ipalib/plugable.py6
-rw-r--r--ipalib/tests/test_backend.py1
-rw-r--r--ipalib/tests/test_plugable.py19
4 files changed, 30 insertions, 2 deletions
diff --git a/ipalib/backend.py b/ipalib/backend.py
index 053609c5..82ed14f3 100644
--- a/ipalib/backend.py
+++ b/ipalib/backend.py
@@ -24,4 +24,8 @@ Base classes for all backed-end plugins.
import plugable
class Backend(plugable.Plugin):
- pass
+ """
+ Base class for all backend plugins.
+ """
+
+ __proxy__ = False # Backend plugins are not wrapped in a PluginProxy
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 6e12d5c7..f883eb12 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -241,6 +241,7 @@ class Plugin(ReadOnly):
Base class for all plugins.
"""
__public__ = frozenset()
+ __proxy__ = True
__api = None
def __get_name(self):
@@ -709,7 +710,10 @@ class API(DictProxy):
if klass not in instances:
instances[klass] = klass()
plugin = instances[klass]
- yield PluginProxy(base, plugin)
+ if base.__proxy__:
+ yield PluginProxy(base, plugin)
+ else:
+ yield plugin
for name in self.register:
base = self.register[name]
diff --git a/ipalib/tests/test_backend.py b/ipalib/tests/test_backend.py
index 2183ed0a..967e9fdf 100644
--- a/ipalib/tests/test_backend.py
+++ b/ipalib/tests/test_backend.py
@@ -34,3 +34,4 @@ class test_Backend(ClassChecker):
def test_class(self):
assert self.cls.__bases__ == (plugable.Plugin,)
+ assert self.cls.__proxy__ is False
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py
index 6c796f9e..02d35cde 100644
--- a/ipalib/tests/test_plugable.py
+++ b/ipalib/tests/test_plugable.py
@@ -795,3 +795,22 @@ def test_API():
# Test that calling finilize again raises AssertionError:
raises(AssertionError, api.finalize)
+
+ # Test with base class that doesn't request a proxy
+ class NoProxy(plugable.Plugin):
+ __proxy__ = False
+ api = plugable.API(NoProxy)
+ class plugin0(NoProxy):
+ pass
+ api.register(plugin0)
+ class plugin1(NoProxy):
+ pass
+ api.register(plugin1)
+ api.finalize()
+ names = ['plugin0', 'plugin1']
+ assert list(api.NoProxy) == names
+ for name in names:
+ plugin = api.NoProxy[name]
+ assert getattr(api.NoProxy, name) is plugin
+ assert isinstance(plugin, plugable.Plugin)
+ assert not isinstance(plugin, plugable.PluginProxy)