mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 08:41:55 -06:00
369: Added Object.backend attribute used to associated it with a particular backend component
This commit is contained in:
parent
433d2e2e11
commit
aa45ec616a
@ -511,17 +511,22 @@ class Command(plugable.Plugin):
|
|||||||
|
|
||||||
class Object(plugable.Plugin):
|
class Object(plugable.Plugin):
|
||||||
__public__ = frozenset((
|
__public__ = frozenset((
|
||||||
|
'backend',
|
||||||
'methods',
|
'methods',
|
||||||
'properties',
|
'properties',
|
||||||
'params',
|
'params',
|
||||||
'primary_key',
|
'primary_key',
|
||||||
'params_minus_pk',
|
'params_minus_pk',
|
||||||
))
|
))
|
||||||
|
backend = None
|
||||||
methods = None
|
methods = None
|
||||||
properties = None
|
properties = None
|
||||||
params = None
|
params = None
|
||||||
primary_key = None
|
primary_key = None
|
||||||
params_minus_pk = None
|
params_minus_pk = None
|
||||||
|
|
||||||
|
# Can override in subclasses:
|
||||||
|
backend_name = None
|
||||||
takes_params = tuple()
|
takes_params = tuple()
|
||||||
|
|
||||||
def set_api(self, api):
|
def set_api(self, api):
|
||||||
@ -549,8 +554,13 @@ class Object(plugable.Plugin):
|
|||||||
filter(lambda p: not p.primary_key, self.params()), sort=False
|
filter(lambda p: not p.primary_key, self.params()), sort=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if 'Backend' in self.api and self.backend_name in self.api.Backend:
|
||||||
|
self.backend = self.api.Backend[self.backend_name]
|
||||||
|
|
||||||
def __get_attrs(self, name):
|
def __get_attrs(self, name):
|
||||||
namespace = getattr(self.api, name)
|
if name not in self.api:
|
||||||
|
return
|
||||||
|
namespace = self.api[name]
|
||||||
assert type(namespace) is plugable.NameSpace
|
assert type(namespace) is plugable.NameSpace
|
||||||
for proxy in namespace(): # Equivalent to dict.itervalues()
|
for proxy in namespace(): # Equivalent to dict.itervalues()
|
||||||
if proxy.obj_name == self.name:
|
if proxy.obj_name == self.name:
|
||||||
|
@ -23,7 +23,7 @@ Unit tests for `ipalib.frontend` module.
|
|||||||
|
|
||||||
from tstutil import raises, getitem, no_set, no_del, read_only, ClassChecker
|
from tstutil import raises, getitem, no_set, no_del, read_only, ClassChecker
|
||||||
from tstutil import check_TypeError
|
from tstutil import check_TypeError
|
||||||
from ipalib import frontend, plugable, errors, ipa_types
|
from ipalib import frontend, backend, plugable, errors, ipa_types
|
||||||
|
|
||||||
|
|
||||||
def test_RULE_FLAG():
|
def test_RULE_FLAG():
|
||||||
@ -760,6 +760,7 @@ class test_Object(ClassChecker):
|
|||||||
|
|
||||||
def test_class(self):
|
def test_class(self):
|
||||||
assert self.cls.__bases__ == (plugable.Plugin,)
|
assert self.cls.__bases__ == (plugable.Plugin,)
|
||||||
|
assert self.cls.backend is None
|
||||||
assert self.cls.methods is None
|
assert self.cls.methods is None
|
||||||
assert self.cls.properties is None
|
assert self.cls.properties is None
|
||||||
assert self.cls.params is None
|
assert self.cls.params is None
|
||||||
@ -771,6 +772,7 @@ class test_Object(ClassChecker):
|
|||||||
Test the `frontend.Object.__init__` method.
|
Test the `frontend.Object.__init__` method.
|
||||||
"""
|
"""
|
||||||
o = self.cls()
|
o = self.cls()
|
||||||
|
assert o.backend is None
|
||||||
assert o.methods is None
|
assert o.methods is None
|
||||||
assert o.properties is None
|
assert o.properties is None
|
||||||
assert o.params is None
|
assert o.params is None
|
||||||
@ -810,13 +812,16 @@ class test_Object(ClassChecker):
|
|||||||
properties='property_%d',
|
properties='property_%d',
|
||||||
)
|
)
|
||||||
|
|
||||||
class api(object):
|
|
||||||
Method = plugable.NameSpace(
|
_d = dict(
|
||||||
|
Method=plugable.NameSpace(
|
||||||
get_attributes(cnt, formats['methods'])
|
get_attributes(cnt, formats['methods'])
|
||||||
)
|
),
|
||||||
Property = plugable.NameSpace(
|
Property=plugable.NameSpace(
|
||||||
get_attributes(cnt, formats['properties'])
|
get_attributes(cnt, formats['properties'])
|
||||||
)
|
),
|
||||||
|
)
|
||||||
|
api = plugable.MagicDict(_d)
|
||||||
assert len(api.Method) == cnt * 3
|
assert len(api.Method) == cnt * 3
|
||||||
assert len(api.Property) == cnt * 3
|
assert len(api.Property) == cnt * 3
|
||||||
|
|
||||||
@ -914,6 +919,27 @@ class test_Object(ClassChecker):
|
|||||||
assert str(e) == \
|
assert str(e) == \
|
||||||
'example3 (Object) has multiple primary keys: one, two, four'
|
'example3 (Object) has multiple primary keys: one, two, four'
|
||||||
|
|
||||||
|
def test_backend(self):
|
||||||
|
"""
|
||||||
|
Test the `frontend.Object.backend` attribute.
|
||||||
|
"""
|
||||||
|
api = plugable.API(
|
||||||
|
frontend.Object,
|
||||||
|
frontend.Method,
|
||||||
|
frontend.Property,
|
||||||
|
backend.Backend,
|
||||||
|
)
|
||||||
|
class ldap(backend.Backend):
|
||||||
|
whatever = 'It worked!'
|
||||||
|
api.register(ldap)
|
||||||
|
class user(frontend.Object):
|
||||||
|
backend_name = 'ldap'
|
||||||
|
api.register(user)
|
||||||
|
api.finalize()
|
||||||
|
b = api.Object.user.backend
|
||||||
|
assert isinstance(b, ldap)
|
||||||
|
assert b.whatever == 'It worked!'
|
||||||
|
|
||||||
|
|
||||||
class test_Attribute(ClassChecker):
|
class test_Attribute(ClassChecker):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user