summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-26 02:43:11 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-26 02:43:11 +0000
commitaa45ec616a0c49a9cedd32fb24aa4a56f69a6586 (patch)
tree6b5f88eb33029b6d040c0e34ade351e31b85b128
parent433d2e2e11a11bfe08599cd2314570d164448afa (diff)
downloadfreeipa-aa45ec616a0c49a9cedd32fb24aa4a56f69a6586.tar.gz
freeipa-aa45ec616a0c49a9cedd32fb24aa4a56f69a6586.tar.xz
freeipa-aa45ec616a0c49a9cedd32fb24aa4a56f69a6586.zip
369: Added Object.backend attribute used to associated it with a particular backend component
-rw-r--r--ipalib/frontend.py12
-rw-r--r--ipalib/tests/test_frontend.py38
2 files changed, 43 insertions, 7 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index c95397aa3..da04cd7a8 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -511,17 +511,22 @@ class Command(plugable.Plugin):
class Object(plugable.Plugin):
__public__ = frozenset((
+ 'backend',
'methods',
'properties',
'params',
'primary_key',
'params_minus_pk',
))
+ backend = None
methods = None
properties = None
params = None
primary_key = None
params_minus_pk = None
+
+ # Can override in subclasses:
+ backend_name = None
takes_params = tuple()
def set_api(self, api):
@@ -549,8 +554,13 @@ class Object(plugable.Plugin):
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):
- namespace = getattr(self.api, name)
+ if name not in self.api:
+ return
+ namespace = self.api[name]
assert type(namespace) is plugable.NameSpace
for proxy in namespace(): # Equivalent to dict.itervalues()
if proxy.obj_name == self.name:
diff --git a/ipalib/tests/test_frontend.py b/ipalib/tests/test_frontend.py
index 1c36d7bdd..d7279c9b1 100644
--- a/ipalib/tests/test_frontend.py
+++ b/ipalib/tests/test_frontend.py
@@ -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 check_TypeError
-from ipalib import frontend, plugable, errors, ipa_types
+from ipalib import frontend, backend, plugable, errors, ipa_types
def test_RULE_FLAG():
@@ -760,6 +760,7 @@ class test_Object(ClassChecker):
def test_class(self):
assert self.cls.__bases__ == (plugable.Plugin,)
+ assert self.cls.backend is None
assert self.cls.methods is None
assert self.cls.properties is None
assert self.cls.params is None
@@ -771,6 +772,7 @@ class test_Object(ClassChecker):
Test the `frontend.Object.__init__` method.
"""
o = self.cls()
+ assert o.backend is None
assert o.methods is None
assert o.properties is None
assert o.params is None
@@ -810,13 +812,16 @@ class test_Object(ClassChecker):
properties='property_%d',
)
- class api(object):
- Method = plugable.NameSpace(
+
+ _d = dict(
+ Method=plugable.NameSpace(
get_attributes(cnt, formats['methods'])
- )
- Property = plugable.NameSpace(
+ ),
+ Property=plugable.NameSpace(
get_attributes(cnt, formats['properties'])
- )
+ ),
+ )
+ api = plugable.MagicDict(_d)
assert len(api.Method) == cnt * 3
assert len(api.Property) == cnt * 3
@@ -914,6 +919,27 @@ class test_Object(ClassChecker):
assert str(e) == \
'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):
"""