summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-13 23:26:24 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-13 23:26:24 -0600
commit446037fd60d59f671b9a402b9111ab041c1c1439 (patch)
treec92d65e2d1c6b58a559119480fcc1a840627cd5a
parent22669f1fc2ffb6de8a8d92a64132dd0b31e877b3 (diff)
downloadfreeipa-446037fd60d59f671b9a402b9111ab041c1c1439.tar.gz
freeipa-446037fd60d59f671b9a402b9111ab041c1c1439.tar.xz
freeipa-446037fd60d59f671b9a402b9111ab041c1c1439.zip
Added Object.get_dn() method; added corresponding unit tests
-rw-r--r--ipa_server/plugins/b_ldap.py3
-rw-r--r--ipalib/frontend.py7
-rw-r--r--tests/test_ipalib/test_frontend.py14
3 files changed, 24 insertions, 0 deletions
diff --git a/ipa_server/plugins/b_ldap.py b/ipa_server/plugins/b_ldap.py
index a8463aa76..827e25120 100644
--- a/ipa_server/plugins/b_ldap.py
+++ b/ipa_server/plugins/b_ldap.py
@@ -23,6 +23,7 @@ Backend plugin for LDAP.
This wraps the python-ldap bindings.
"""
+import ldap as _ldap
from ipalib import api
from ipalib.backend import Backend
@@ -32,4 +33,6 @@ class ldap(Backend):
LDAP backend plugin.
"""
+ dn = _ldap.dn
+
api.register(ldap)
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 50e2dd3e0..65b053e6c 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -750,6 +750,7 @@ class Object(plugable.Plugin):
'params',
'primary_key',
'params_minus_pk',
+ 'get_dn',
))
backend = None
methods = None
@@ -790,6 +791,12 @@ class Object(plugable.Plugin):
if 'Backend' in self.api and self.backend_name in self.api.Backend:
self.backend = self.api.Backend[self.backend_name]
+ def get_dn(self, primary_key):
+ """
+ Construct an LDAP DN from a primary_key.
+ """
+ raise NotImplementedError('%s.get_dn()' % self.name)
+
def __get_attrs(self, name):
if name not in self.api:
return
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 297aa8da6..9ab0504b2 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -963,6 +963,20 @@ class test_Object(ClassChecker):
assert isinstance(b, ldap)
assert b.whatever == 'It worked!'
+ def test_get_dn(self):
+ """
+ Test the `ipalib.frontend.Object.get_dn` method.
+ """
+ assert 'get_dn' in self.cls.__public__ # Public
+ o = self.cls()
+ e = raises(NotImplementedError, o.get_dn, 'primary key')
+ assert str(e) == 'Object.get_dn()'
+ class user(self.cls):
+ pass
+ o = user()
+ e = raises(NotImplementedError, o.get_dn, 'primary key')
+ assert str(e) == 'user.get_dn()'
+
class test_Attribute(ClassChecker):
"""