summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tests/python
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-05-19 23:07:04 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-05-19 23:07:04 +0200
commitae4611909609b8a0466938171812f10974dc054a (patch)
treec478b6237d6fc8cd201211264bd8d24bd105aa5f /source4/lib/ldb/tests/python
parentd817b435342956295f0a31b91203d1a63ae12063 (diff)
downloadsamba-ae4611909609b8a0466938171812f10974dc054a.tar.gz
samba-ae4611909609b8a0466938171812f10974dc054a.tar.bz2
samba-ae4611909609b8a0466938171812f10974dc054a.zip
Add __repr__ implementations for ldb.Message, ldb.MessageElement and ldb.Dn.
(This used to be commit b9119c0f0f524d43ff09825dffb24a5e77a240f4)
Diffstat (limited to 'source4/lib/ldb/tests/python')
-rwxr-xr-xsource4/lib/ldb/tests/python/api.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py
index 5f3f727b5d..6f073f79a8 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -60,6 +60,10 @@ class SimpleLdb(unittest.TestCase):
l = ldb.Ldb("foo.tdb")
self.assertEquals(len(l.search("", ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0)
+ def test_search_attr_string(self):
+ l = ldb.Ldb("foo.tdb")
+ self.assertRaises(TypeError, l.search, attrs="dc")
+
def test_opaque(self):
l = ldb.Ldb("foo.tdb")
l.set_opaque("my_opaque", l)
@@ -257,6 +261,10 @@ class DnTests(unittest.TestCase):
x = ldb.Dn(self.ldb, "dc=foo,bar=bloe")
self.assertEquals(x.__str__(), "dc=foo,bar=bloe")
+ def test_repr(self):
+ x = ldb.Dn(self.ldb, "dc=foo,bla=blie")
+ self.assertEquals(x.__repr__(), "Dn('dc=foo,bla=blie')")
+
def test_get_casefold(self):
x = ldb.Dn(self.ldb, "dc=foo,bar=bloe")
self.assertEquals(x.get_casefold(), "DC=FOO,BAR=bloe")
@@ -347,6 +355,16 @@ class LdbMsgTests(unittest.TestCase):
self.msg = ldb.Message(ldb.Dn(ldb.Ldb(), "dc=foo"))
self.assertEquals("dc=foo", str(self.msg.dn))
+ def test_iter_items(self):
+ self.assertEquals(0, len(self.msg.items()))
+ self.msg.dn = ldb.Dn(ldb.Ldb("foo.tdb"), "dc=foo")
+ self.assertEquals(1, len(self.msg.items()))
+
+ def test_repr(self):
+ self.msg.dn = ldb.Dn(ldb.Ldb("foo.tdb"), "dc=foo")
+ self.msg["dc"] = "foo"
+ self.assertEquals("Message({'dn': Dn('dc=foo'), 'dc': MessageElement(['foo'])})", repr(self.msg))
+
def test_len(self):
self.assertEquals(0, len(self.msg))
@@ -374,14 +392,26 @@ class LdbMsgTests(unittest.TestCase):
self.assertEquals(["bar"], list(self.msg["foo"]))
def test_keys(self):
+ self.msg.dn = ldb.Dn(ldb.Ldb("foo.tdb"), "@BASEINFO")
self.msg["foo"] = ["bla"]
self.msg["bar"] = ["bla"]
- self.assertEquals(["foo", "bar"], self.msg.keys())
+ self.assertEquals(["dn", "foo", "bar"], self.msg.keys())
def test_dn(self):
self.msg.dn = ldb.Dn(ldb.Ldb("foo.tdb"), "@BASEINFO")
self.assertEquals("@BASEINFO", self.msg.dn.__str__())
+ def test_get_dn(self):
+ self.msg.dn = ldb.Dn(ldb.Ldb("foo.tdb"), "@BASEINFO")
+ self.assertEquals("@BASEINFO", self.msg.get("dn").__str__())
+
+ def test_get_other(self):
+ self.msg["foo"] = ["bar"]
+ self.assertEquals("bar", self.msg.get("foo")[0])
+
+ def test_get_unknown(self):
+ self.assertRaises(KeyError, self.msg.get, "lalalala")
+
class MessageElementTests(unittest.TestCase):
def test_cmp_element(self):
@@ -395,6 +425,12 @@ class MessageElementTests(unittest.TestCase):
x = ldb.MessageElement(["foo"])
self.assertEquals(["foo"], list(x))
+ def test_repr(self):
+ x = ldb.MessageElement(["foo"])
+ self.assertEquals("MessageElement(['foo'])", repr(x))
+ x = ldb.MessageElement(["foo", "bla"])
+ self.assertEquals("MessageElement(['foo','bla'])", repr(x))
+
def test_get_item(self):
x = ldb.MessageElement(["foo", "bar"])
self.assertEquals("foo", x[0])