Removed PluginProxy and all its uses

This commit is contained in:
Jason Gerard DeRose
2009-08-04 02:41:11 -06:00
committed by Rob Crittenden
parent b7b9f9b6a6
commit c0f558d98b
7 changed files with 35 additions and 287 deletions

View File

@@ -666,7 +666,7 @@ class test_Object(ClassChecker):
assert attr is getattr(namespace, attr_name)
assert attr.obj_name == 'user'
assert attr.attr_name == attr_name
assert attr.name == attr_name
assert attr.name == '%s_%s' % ('user', attr_name)
# Test params instance attribute
o = self.cls()

View File

@@ -377,128 +377,6 @@ class test_Plugin(ClassChecker):
assert e.argv == ('/bin/false',)
class test_PluginProxy(ClassChecker):
"""
Test the `ipalib.plugable.PluginProxy` class.
"""
_cls = plugable.PluginProxy
def test_class(self):
"""
Test the `ipalib.plugable.PluginProxy` class.
"""
assert self.cls.__bases__ == (plugable.SetProxy,)
def test_proxy(self):
"""
Test proxy behaviour of `ipalib.plugable.PluginProxy` instance.
"""
# Setup:
class base(object):
__public__ = frozenset((
'public_0',
'public_1',
'__call__',
))
def public_0(self):
return 'public_0'
def public_1(self):
return 'public_1'
def __call__(self, caller):
return 'ya called it, %s.' % caller
def private_0(self):
return 'private_0'
def private_1(self):
return 'private_1'
class plugin(base):
name = 'user_add'
attr_name = 'add'
doc = 'add a new user'
# Test that TypeError is raised when base is not a class:
raises(TypeError, self.cls, base(), None)
# Test that ValueError is raised when target is not instance of base:
raises(ValueError, self.cls, base, object())
# Test with correct arguments:
i = plugin()
p = self.cls(base, i)
assert read_only(p, 'name') is plugin.name
assert read_only(p, 'doc') == plugin.doc
assert list(p) == sorted(base.__public__)
# Test normal methods:
for n in xrange(2):
pub = 'public_%d' % n
priv = 'private_%d' % n
assert getattr(i, pub)() == pub
assert getattr(p, pub)() == pub
assert hasattr(p, pub)
assert getattr(i, priv)() == priv
assert not hasattr(p, priv)
# Test __call__:
value = 'ya called it, dude.'
assert i('dude') == value
assert p('dude') == value
assert callable(p)
# Test name_attr='name' kw arg
i = plugin()
p = self.cls(base, i, 'attr_name')
assert read_only(p, 'name') == 'add'
def test_implements(self):
"""
Test the `ipalib.plugable.PluginProxy.implements` method.
"""
class base(object):
__public__ = frozenset()
name = 'base'
doc = 'doc'
@classmethod
def implements(cls, arg):
return arg + 7
class sub(base):
@classmethod
def implements(cls, arg):
"""
Defined to make sure base.implements() is called, not
target.implements()
"""
return arg
o = sub()
p = self.cls(base, o)
assert p.implements(3) == 10
def test_clone(self):
"""
Test the `ipalib.plugable.PluginProxy.__clone__` method.
"""
class base(object):
__public__ = frozenset()
class sub(base):
name = 'some_name'
doc = 'doc'
label = 'another_name'
p = self.cls(base, sub())
assert read_only(p, 'name') == 'some_name'
c = p.__clone__('label')
assert isinstance(c, self.cls)
assert c is not p
assert read_only(c, 'name') == 'another_name'
def test_Registrar():
"""
Test the `ipalib.plugable.Registrar` class
@@ -682,50 +560,34 @@ class test_API(ClassChecker):
assert api.isdone('bootstrap') is True
assert api.isdone('finalize') is True
def get_base(b):
def get_base_name(b):
return 'base%d' % b
def get_plugin(b, p):
def get_plugin_name(b, p):
return 'base%d_plugin%d' % (b, p)
for b in xrange(2):
base_name = get_base(b)
base_name = get_base_name(b)
base = locals()[base_name]
ns = getattr(api, base_name)
assert isinstance(ns, plugable.NameSpace)
assert read_only(api, base_name) is ns
assert len(ns) == 3
for p in xrange(3):
plugin_name = get_plugin(b, p)
proxy = ns[plugin_name]
assert isinstance(proxy, plugable.PluginProxy)
assert proxy.name == plugin_name
assert read_only(ns, plugin_name) is proxy
assert read_only(proxy, 'method')(7) == 7 + b
plugin_name = get_plugin_name(b, p)
plugin = locals()[plugin_name]
inst = ns[plugin_name]
assert isinstance(inst, base)
assert isinstance(inst, plugin)
assert inst.name == plugin_name
assert read_only(ns, plugin_name) is inst
assert inst.method(7) == 7 + b
# Test that calling finilize again raises AssertionError:
e = raises(StandardError, api.finalize)
assert str(e) == 'API.finalize() already called', str(e)
# Test with base class that doesn't request a proxy
class NoProxy(plugable.Plugin):
__proxy__ = False
api = plugable.API(NoProxy)
api.env.mode = 'unit_test'
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)
def test_bootstrap(self):
"""
Test the `ipalib.plugable.API.bootstrap` method.