From ea851658411e3ff03a906f7ae6afc7e9319d6f90 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 11:47:55 +0100 Subject: r26068: Import improved Python bindings for LDB, including tests. (This used to be commit fc3a8caef749ddac56a4f035dde8b6ceeaa95c48) --- source4/lib/ldb/tests/python/api.py | 353 ++++++++++++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100755 source4/lib/ldb/tests/python/api.py (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py new file mode 100755 index 0000000000..b140bfc599 --- /dev/null +++ b/source4/lib/ldb/tests/python/api.py @@ -0,0 +1,353 @@ +#!/usr/bin/python +# Simple tests for the ldb python API +# Copyright (C) 2007 Jelmer Vernooij +import sys +import unittest +sys.path.append("swig") +sys.path.append("build/lib.linux-i686-2.4") + +import ldb + +class NoContextTests(unittest.TestCase): + def test_valid_attr_name(self): + self.assertTrue(ldb.valid_attr_name("foo")) + self.assertFalse(ldb.valid_attr_name("24foo")) + + def test_timestring(self): + self.assertEquals("19700101000000.0Z", ldb.timestring(0)) + self.assertEquals("20071119191012.0Z", ldb.timestring(1195499412)) + + def test_string_to_time(self): + self.assertEquals(0, ldb.string_to_time("19700101000000.0Z")) + self.assertEquals(1195499412, ldb.string_to_time("20071119191012.0Z")) + + +class SimpleLdb(unittest.TestCase): + def test_connect(self): + ldb.Ldb("foo.tdb") + + def test_connect_none(self): + ldb.Ldb() + + def test_connect_later(self): + x = ldb.Ldb() + x.connect("foo.tdb") + + def test_set_create_perms(self): + x = ldb.Ldb() + x.set_create_perms(0600) + + def test_set_modules_dir(self): + x = ldb.Ldb() + x.set_modules_dir("/tmp") + + def test_search(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(len(l.search()), 1) + + def test_search_attrs(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) + + def test_opaque(self): + l = ldb.Ldb("foo.tdb") + l.set_opaque("my_opaque", l) + self.assertTrue(l.get_opaque("my_opaque") is not None) + self.assertEquals(None, l.get_opaque("unknown")) + + def test_search_scope_base(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(len(l.search(ldb.Dn(l, "dc=foo"), + ldb.SCOPE_ONELEVEL)), 0) + + def test_delete(self): + l = ldb.Ldb("foo.tdb") + self.assertRaises(ldb.LdbError, lambda: l.delete(ldb.Dn(l, "dc=foo"))) + + def test_contains(self): + l = ldb.Ldb("foo.tdb") + self.assertFalse(ldb.Dn(l, "dc=foo") in l) + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=foo") + m["b"] = ["a"] + l.add(m) + try: + self.assertTrue(ldb.Dn(l, "dc=foo") in l) + finally: + l.delete(m.dn) + + def test_get_config_basedn(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(None, l.get_config_basedn()) + + def test_get_root_basedn(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(None, l.get_root_basedn()) + + def test_get_schema_basedn(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(None, l.get_schema_basedn()) + + def test_get_default_basedn(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(None, l.get_default_basedn()) + + def test_add(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=foo") + m["bla"] = "bla" + self.assertEquals(len(l.search()), 1) + l.add(m) + try: + self.assertEquals(len(l.search()), 2) + finally: + l.delete(ldb.Dn(l, "dc=foo")) + + def test_add_dict(self): + l = ldb.Ldb("foo.tdb") + m = {"dn": ldb.Dn(l, "dc=foo"), + "bla": "bla"} + self.assertEquals(len(l.search()), 1) + l.add(m) + try: + self.assertEquals(len(l.search()), 2) + finally: + l.delete(ldb.Dn(l, "dc=foo")) + + def test_rename(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=foo") + m["bla"] = "bla" + self.assertEquals(len(l.search()), 1) + l.add(m) + try: + l.rename(ldb.Dn(l, "dc=foo"), ldb.Dn(l, "dc=bar")) + self.assertEquals(len(l.search()), 2) + finally: + l.delete(ldb.Dn(l, "dc=bar")) + + def test_modify_delete(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=modify") + m["bla"] = ["1234"] + l.add(m) + rm = l.search(m.dn)[0] + self.assertEquals(["1234"], list(rm["bla"])) + try: + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=modify") + m["bla"] = ldb.MessageElement([], ldb.CHANGETYPE_DELETE, "bla") + l.modify(m) + rm = l.search(m.dn)[0] + self.assertEquals(1, len(rm)) + finally: + l.delete(ldb.Dn(l, "dc=modify")) + + def test_modify_add(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=modify") + m["bla"] = ["1234"] + l.add(m) + try: + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=modify") + m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_ADD, "bla") + l.modify(m) + rm = l.search(m.dn)[0] + self.assertEquals(2, len(rm)) + self.assertEquals(["1234", "456"], list(rm["bla"])) + finally: + l.delete(ldb.Dn(l, "dc=modify")) + + def test_modify_modify(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=modify") + m["bla"] = ["1234", "456"] + l.add(m) + try: + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=modify") + m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_MODIFY, "bla") + l.modify(m) + rm = l.search(m.dn)[0] + self.assertEquals(2, len(rm)) + self.assertEquals(["1234"], list(rm["bla"])) + finally: + l.delete(ldb.Dn(l, "dc=modify")) + + def test_transaction_commit(self): + l = ldb.Ldb("foo.tdb") + l.transaction_start() + m = ldb.Message(ldb.Dn(l, "dc=foo")) + m["foo"] = ["bar"] + l.add(m) + l.transaction_commit() + l.delete(m.dn) + + def test_transaction_cancel(self): + l = ldb.Ldb("foo.tdb") + l.transaction_start() + m = ldb.Message(ldb.Dn(l, "dc=foo")) + m["foo"] = ["bar"] + l.add(m) + l.transaction_cancel() + self.assertEquals(0, len(l.search(ldb.Dn(l, "dc=foo")))) + + def test_set_debug(self): + def my_report_fn(level, text): + pass + l = ldb.Ldb("foo.tdb") + l.set_debug(my_report_fn) + + +class DnTests(unittest.TestCase): + def setUp(self): + self.ldb = ldb.Ldb("foo.tdb") + + def test_str(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals(x.__str__(), "dc=foo,bar=bloe") + + def test_get_casefold(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals(x.get_casefold(), "DC=FOO,BAR=bloe") + + def test_validate(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertTrue(x.validate()) + + def test_parent(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals("bar=bloe", x.parent().__str__()) + + def test_compare(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + y = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals(x, y) + z = ldb.Dn(self.ldb, "dc=foo,bar=blie") + self.assertNotEquals(z, y) + + def test_is_valid(self): + x = ldb.Dn(self.ldb, "dc=foo,dc=bloe") + self.assertTrue(x.is_valid()) + x = ldb.Dn(self.ldb, "") + # is_valid()'s return values appears to be a side effect of + # some other ldb functions. yuck. + # self.assertFalse(x.is_valid()) + + def test_is_special(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertFalse(x.is_special()) + x = ldb.Dn(self.ldb, "@FOOBAR") + self.assertTrue(x.is_special()) + + def test_check_special(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertFalse(x.check_special("FOOBAR")) + x = ldb.Dn(self.ldb, "@FOOBAR") + self.assertTrue(x.check_special("@FOOBAR")) + + def test_len(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals(2, len(x)) + x = ldb.Dn(self.ldb, "dc=foo") + self.assertEquals(1, len(x)) + + def test_add_child(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertTrue(x.add_child(ldb.Dn(self.ldb, "bla=bloe"))) + self.assertEquals("bla=bloe,dc=foo,bar=bloe", x.__str__()) + + def test_add_base(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertTrue(x.add_base(ldb.Dn(self.ldb, "bla=bloe"))) + self.assertEquals("dc=foo,bar=bloe,bla=bloe", x.__str__()) + + def test_add(self): + x = ldb.Dn(self.ldb, "dc=foo") + y = ldb.Dn(self.ldb, "bar=bla") + self.assertEquals("dc=foo,bar=bla", str(y + x)) + + def test_parse_ldif(self): + msgs = self.ldb.parse_ldif("dn: foo=bar\n") + msg = msgs.next() + self.assertEquals("foo=bar", str(msg[1].dn)) + self.assertTrue(isinstance(msg[1], ldb.Message)) + + def test_parse_ldif_more(self): + msgs = self.ldb.parse_ldif("dn: foo=bar\n\n\ndn: bar=bar") + msg = msgs.next() + self.assertEquals("foo=bar", str(msg[1].dn)) + msg = msgs.next() + self.assertEquals("bar=bar", str(msg[1].dn)) + + def test_canonical_string(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals("/bloe/foo", x.canonical_str()) + + def test_canonical_ex_string(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals("/bloe\nfoo", x.canonical_ex_str()) + + +class LdbMsgTests(unittest.TestCase): + def setUp(self): + self.msg = ldb.Message() + + def test_init_dn(self): + self.msg = ldb.Message(ldb.Dn(ldb.Ldb(), "dc=foo")) + self.assertEquals("dc=foo", str(self.msg.dn)) + + def test_len(self): + self.assertEquals(0, len(self.msg)) + + def test_notpresent(self): + self.assertRaises(KeyError, lambda: self.msg["foo"]) + + def test_del(self): + del self.msg["foo"] + + def test_add_value(self): + self.assertEquals(0, len(self.msg)) + self.msg["foo"] = ["foo"] + self.assertEquals(1, len(self.msg)) + + def test_add_value_multiple(self): + self.assertEquals(0, len(self.msg)) + self.msg["foo"] = ["foo", "bla"] + self.assertEquals(1, len(self.msg)) + self.assertEquals(["foo", "bla"], list(self.msg["foo"])) + + def test_set_value(self): + self.msg["foo"] = ["fool"] + self.assertEquals(["fool"], list(self.msg["foo"])) + self.msg["foo"] = ["bar"] + self.assertEquals(["bar"], list(self.msg["foo"])) + + def test_keys(self): + self.msg["foo"] = ["bla"] + self.msg["bar"] = ["bla"] + self.assertEquals(["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__()) + + +class MessageElementTests(unittest.TestCase): + def test_cmp_element(self): + x = ldb.MessageElement(["foo"]) + y = ldb.MessageElement(["foo"]) + z = ldb.MessageElement(["bzr"]) + self.assertEquals(x, y) + self.assertNotEquals(x, z) + + def test_create_iterable(self): + x = ldb.MessageElement(["foo"]) + self.assertEquals(["foo"], list(x)) -- cgit From 07beaf09c95a06636cb029fcc2dbbeb7293879ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 17 Dec 2007 03:25:28 +0100 Subject: r26480: Add utility class for testing LDB code. (This used to be commit d7f0b12c9e43b93705f6b9fa6b5ab74fe68e80a0) --- source4/lib/ldb/tests/python/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index b140bfc599..3b4de044b0 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -1,8 +1,11 @@ #!/usr/bin/python -# Simple tests for the ldb python API +# Simple tests for the ldb python bindings. # Copyright (C) 2007 Jelmer Vernooij + import sys import unittest + +# Required for the standalone LDB build sys.path.append("swig") sys.path.append("build/lib.linux-i686-2.4") -- cgit From 6e2459211dbd59c8884049faa0d63c1712dbadfe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 19 Dec 2007 23:27:34 +0100 Subject: r26537: Support ldb.add({'dn': 'dc=foo,bar=bla', ...}). (This used to be commit e91fe76d296973430f71502c9b614d0dfac4d83c) --- source4/lib/ldb/tests/python/api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 3b4de044b0..b6d6170ec2 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -119,6 +119,16 @@ class SimpleLdb(unittest.TestCase): finally: l.delete(ldb.Dn(l, "dc=foo")) + def test_add_dict_string_dn(self): + l = ldb.Ldb("foo.tdb") + m = {"dn": "dc=foo", "bla": "bla"} + self.assertEquals(len(l.search()), 1) + l.add(m) + try: + self.assertEquals(len(l.search()), 2) + finally: + l.delete(ldb.Dn(l, "dc=foo")) + def test_rename(self): l = ldb.Ldb("foo.tdb") m = ldb.Message() -- cgit From fb021305e4bc1175ae0d1960fbafc7eba29ef2f0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 22 Dec 2007 14:28:45 -0600 Subject: r26567: Allow registering new ldb modules from python. (This used to be commit 485db76d8476fce399a9b6cb977cf55ea35ec189) --- source4/lib/ldb/tests/python/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index b6d6170ec2..c280a3f3c4 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -364,3 +364,11 @@ class MessageElementTests(unittest.TestCase): def test_create_iterable(self): x = ldb.MessageElement(["foo"]) self.assertEquals(["foo"], list(x)) + +class ExampleModule: + name = "example" + +class ModuleTests(unittest.TestCase): + def test_register_module(self): + ldb.register_module(ExampleModule()) + -- cgit From aa0a06f13c44e0eca0b3f2f0c34f0f7995b87159 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 19:19:41 -0600 Subject: r26570: - Trim size of the swig-generated Python bindings by removing a bunch of {}'s. - Start working on Python equivalents for various EJS tests. - Fix regression in argument order for reg_diff_apply() in EJS bindings. (This used to be commit c550c03372cb260b78f6a6c132e70571bc4cb852) --- source4/lib/ldb/tests/python/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index c280a3f3c4..d9dfce8718 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -52,6 +52,10 @@ class SimpleLdb(unittest.TestCase): l = ldb.Ldb("foo.tdb") self.assertEquals(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) + def test_search_string_dn(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(len(l.search("", ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) + def test_opaque(self): l = ldb.Ldb("foo.tdb") l.set_opaque("my_opaque", l) @@ -142,6 +146,19 @@ class SimpleLdb(unittest.TestCase): finally: l.delete(ldb.Dn(l, "dc=bar")) + def test_rename_string_dns(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=foo") + m["bla"] = "bla" + self.assertEquals(len(l.search()), 1) + l.add(m) + try: + l.rename("dc=foo", "dc=bar") + self.assertEquals(len(l.search()), 2) + finally: + l.delete(ldb.Dn(l, "dc=bar")) + def test_modify_delete(self): l = ldb.Ldb("foo.tdb") m = ldb.Message() -- cgit From 9269db983d847be7a0cdc9eb2bcc4ebe3066be1c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 00:23:33 +0100 Subject: python/ldb: Add __getitem__ implementation for LdbMessageElement. (This used to be commit e6498a0780dd31dfc623a69432004b606aeaccbe) --- source4/lib/ldb/tests/python/api.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index d9dfce8718..0a5ba035ff 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -382,6 +382,12 @@ class MessageElementTests(unittest.TestCase): x = ldb.MessageElement(["foo"]) self.assertEquals(["foo"], list(x)) + def test_get_item(self): + x = ldb.MessageElement(["foo", "bar"]) + self.assertEquals("foo", x[0]) + self.assertEquals("bar", x[1]) + self.assertRaises(KeyError, lambda: x[-1]) + class ExampleModule: name = "example" -- cgit From c3695026e1cfac3e835e937ed9343d82500cf197 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 01:02:58 +0100 Subject: ldb/python: Implement __len__ for MessageElement. (This used to be commit a8f90ed34ce9341080b63c801ef54b82de42b8e6) --- source4/lib/ldb/tests/python/api.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 0a5ba035ff..5ab40106a8 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -388,6 +388,10 @@ class MessageElementTests(unittest.TestCase): self.assertEquals("bar", x[1]) self.assertRaises(KeyError, lambda: x[-1]) + def test_len(self): + x = ldb.MessageElement(["foo", "bar"]) + self.assertEquals(2, len(x)) + class ExampleModule: name = "example" -- cgit From 2466d2cc5e210a124bb23cb9d2c8d3cc608a7c7f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 01:55:56 +0100 Subject: ldb/python: Allow comparing a MessageElement to a list or a singleton. (This used to be commit 1ccbab81d79f83bb419104f2bbaf2ae7b368e90f) --- source4/lib/ldb/tests/python/api.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 5ab40106a8..8469e8f3cd 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -392,6 +392,12 @@ class MessageElementTests(unittest.TestCase): x = ldb.MessageElement(["foo", "bar"]) self.assertEquals(2, len(x)) + def test_eq(self): + x = ldb.MessageElement(["foo", "bar"]) + self.assertEquals(["foo", "bar"], x) + x = ldb.MessageElement(["foo"]) + self.assertEquals("foo", x) + class ExampleModule: name = "example" -- cgit From 1f4838b8a3e5f0c7c400097f56329e5a133ec4e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 02:36:59 +0100 Subject: python/ldap: Wrap parse_control_strings(). (This used to be commit b27e5a68530c4fd6430cbb174b63f8ff2b6f4e53) --- source4/lib/ldb/tests/python/api.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 8469e8f3cd..236698e382 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -62,6 +62,11 @@ class SimpleLdb(unittest.TestCase): self.assertTrue(l.get_opaque("my_opaque") is not None) self.assertEquals(None, l.get_opaque("unknown")) + def test_parse_control_strings(self): + l = ldb.Ldb("foo.tdb") + self.assertRaises(ldb.LdbError, l.parse_control_strings, ["foo", "bar"]) + self.assertTrue(l.parse_control_strings(["paged_results:1:5"]) is not None) + def test_search_scope_base(self): l = ldb.Ldb("foo.tdb") self.assertEquals(len(l.search(ldb.Dn(l, "dc=foo"), -- cgit From 1d8cdddcd0901c5886099b7596f6d9629bdfad69 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 03:25:22 +0100 Subject: python/ldap: Support controls argument to ldb.search(). (This used to be commit 9eddc27f13fa2feb56d6b015e66d8c54081487da) --- source4/lib/ldb/tests/python/api.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 236698e382..b071b84b19 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -48,6 +48,10 @@ class SimpleLdb(unittest.TestCase): l = ldb.Ldb("foo.tdb") self.assertEquals(len(l.search()), 1) + def test_search_controls(self): + l = ldb.Ldb("foo.tdb") + self.assertEquals(len(l.search(controls=["paged_results:1:5"])), 1) + def test_search_attrs(self): l = ldb.Ldb("foo.tdb") self.assertEquals(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) @@ -167,54 +171,54 @@ class SimpleLdb(unittest.TestCase): def test_modify_delete(self): l = ldb.Ldb("foo.tdb") m = ldb.Message() - m.dn = ldb.Dn(l, "dc=modify") + m.dn = ldb.Dn(l, "dc=modifydelete") m["bla"] = ["1234"] l.add(m) rm = l.search(m.dn)[0] self.assertEquals(["1234"], list(rm["bla"])) try: m = ldb.Message() - m.dn = ldb.Dn(l, "dc=modify") + m.dn = ldb.Dn(l, "dc=modifydelete") m["bla"] = ldb.MessageElement([], ldb.CHANGETYPE_DELETE, "bla") l.modify(m) rm = l.search(m.dn)[0] self.assertEquals(1, len(rm)) finally: - l.delete(ldb.Dn(l, "dc=modify")) + l.delete(ldb.Dn(l, "dc=modifydelete")) def test_modify_add(self): l = ldb.Ldb("foo.tdb") m = ldb.Message() - m.dn = ldb.Dn(l, "dc=modify") + m.dn = ldb.Dn(l, "dc=add") m["bla"] = ["1234"] l.add(m) try: m = ldb.Message() - m.dn = ldb.Dn(l, "dc=modify") + m.dn = ldb.Dn(l, "dc=add") m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_ADD, "bla") l.modify(m) rm = l.search(m.dn)[0] self.assertEquals(2, len(rm)) self.assertEquals(["1234", "456"], list(rm["bla"])) finally: - l.delete(ldb.Dn(l, "dc=modify")) + l.delete(ldb.Dn(l, "dc=add")) def test_modify_modify(self): l = ldb.Ldb("foo.tdb") m = ldb.Message() - m.dn = ldb.Dn(l, "dc=modify") + m.dn = ldb.Dn(l, "dc=modify2") m["bla"] = ["1234", "456"] l.add(m) try: m = ldb.Message() - m.dn = ldb.Dn(l, "dc=modify") + m.dn = ldb.Dn(l, "dc=modify2") m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_MODIFY, "bla") l.modify(m) rm = l.search(m.dn)[0] self.assertEquals(2, len(rm)) self.assertEquals(["1234"], list(rm["bla"])) finally: - l.delete(ldb.Dn(l, "dc=modify")) + l.delete(ldb.Dn(l, "dc=modify2")) def test_transaction_commit(self): l = ldb.Ldb("foo.tdb") -- cgit From 79d466c37397a9d3d236f1c81d7d7fda479bd052 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 04:05:41 +0100 Subject: ldb/python: Support comparing Dn's to strings. (This used to be commit 355878907970b396e4031426fda260d981c417eb) --- source4/lib/ldb/tests/python/api.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index b071b84b19..d5346c30b0 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -249,6 +249,10 @@ class DnTests(unittest.TestCase): def setUp(self): self.ldb = ldb.Ldb("foo.tdb") + def test_eq_str(self): + x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") + self.assertEquals("dc=foo,bar=bloe", x) + def test_str(self): x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") self.assertEquals(x.__str__(), "dc=foo,bar=bloe") -- cgit From 1529331b97cc67869f07c2cfa8c73616f3247b73 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 12 Feb 2008 01:21:10 +0100 Subject: Avoid using setup.py for intsallation. (This used to be commit 7b93e43dad55454e9107a38e67764e08f51392d3) --- source4/lib/ldb/tests/python/api.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index d5346c30b0..5f3f727b5d 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -418,3 +418,6 @@ class ModuleTests(unittest.TestCase): def test_register_module(self): ldb.register_module(ExampleModule()) +if __name__ == '__main__': + import unittest + unittest.TestProgram() -- cgit From ae4611909609b8a0466938171812f10974dc054a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 May 2008 23:07:04 +0200 Subject: Add __repr__ implementations for ldb.Message, ldb.MessageElement and ldb.Dn. (This used to be commit b9119c0f0f524d43ff09825dffb24a5e77a240f4) --- source4/lib/ldb/tests/python/api.py | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tests/python/api.py') 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]) -- cgit From 43a22c9b4a7868a740e2de417f50702209d2aced Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 May 2008 23:12:13 +0200 Subject: Add __repr__ implementation for Ldb. (This used to be commit 5607aea07f66f09fd5b33842d07d2fbbf44d13e7) --- source4/lib/ldb/tests/python/api.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 6f073f79a8..1ae3fde744 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -36,6 +36,10 @@ class SimpleLdb(unittest.TestCase): x = ldb.Ldb() x.connect("foo.tdb") + def test_repr(self): + x = ldb.Ldb() + self.assertTrue(repr(x).startswith(" Date: Fri, 12 Sep 2008 13:26:45 -0400 Subject: Fix spellings and file names (This used to be commit baddefd0a6fa430af1a3001064149127e0d29361) --- source4/lib/ldb/tests/python/api.py | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'source4/lib/ldb/tests/python/api.py') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 1ae3fde744..99ad1a9e66 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -27,14 +27,14 @@ class NoContextTests(unittest.TestCase): class SimpleLdb(unittest.TestCase): def test_connect(self): - ldb.Ldb("foo.tdb") + ldb.Ldb("foo.ldb") def test_connect_none(self): ldb.Ldb() def test_connect_later(self): x = ldb.Ldb() - x.connect("foo.tdb") + x.connect("foo.ldb") def test_repr(self): x = ldb.Ldb() @@ -49,19 +49,19 @@ class SimpleLdb(unittest.TestCase): x.set_modules_dir("/tmp") def test_search(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(len(l.search()), 1) def test_search_controls(self): - l = ldb.Ldb("foo.tdb") - self.assertEquals(len(l.search(controls=["paged_results:1:5"])), 1) + l = ldb.Ldb("foo.ldb") + self.assertEquals(len(l.search(controls=["paged_results:0:5"])), 1) def test_search_attrs(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) def test_search_string_dn(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(len(l.search("", ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) def test_search_attr_string(self): @@ -69,29 +69,29 @@ class SimpleLdb(unittest.TestCase): self.assertRaises(TypeError, l.search, attrs="dc") def test_opaque(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") l.set_opaque("my_opaque", l) self.assertTrue(l.get_opaque("my_opaque") is not None) self.assertEquals(None, l.get_opaque("unknown")) def test_parse_control_strings(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertRaises(ldb.LdbError, l.parse_control_strings, ["foo", "bar"]) - self.assertTrue(l.parse_control_strings(["paged_results:1:5"]) is not None) + self.assertTrue(l.parse_control_strings(["paged_results:0:5"]) is not None) def test_search_scope_base(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(len(l.search(ldb.Dn(l, "dc=foo"), ldb.SCOPE_ONELEVEL)), 0) def test_delete(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertRaises(ldb.LdbError, lambda: l.delete(ldb.Dn(l, "dc=foo"))) def test_contains(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertFalse(ldb.Dn(l, "dc=foo") in l) - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=foo") m["b"] = ["a"] @@ -102,23 +102,23 @@ class SimpleLdb(unittest.TestCase): l.delete(m.dn) def test_get_config_basedn(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(None, l.get_config_basedn()) def test_get_root_basedn(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(None, l.get_root_basedn()) def test_get_schema_basedn(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(None, l.get_schema_basedn()) def test_get_default_basedn(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") self.assertEquals(None, l.get_default_basedn()) def test_add(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=foo") m["bla"] = "bla" @@ -130,7 +130,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=foo")) def test_add_dict(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = {"dn": ldb.Dn(l, "dc=foo"), "bla": "bla"} self.assertEquals(len(l.search()), 1) @@ -141,7 +141,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=foo")) def test_add_dict_string_dn(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = {"dn": "dc=foo", "bla": "bla"} self.assertEquals(len(l.search()), 1) l.add(m) @@ -151,7 +151,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=foo")) def test_rename(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=foo") m["bla"] = "bla" @@ -164,7 +164,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=bar")) def test_rename_string_dns(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=foo") m["bla"] = "bla" @@ -177,7 +177,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=bar")) def test_modify_delete(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=modifydelete") m["bla"] = ["1234"] @@ -195,7 +195,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=modifydelete")) def test_modify_add(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=add") m["bla"] = ["1234"] @@ -212,7 +212,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=add")) def test_modify_modify(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") m = ldb.Message() m.dn = ldb.Dn(l, "dc=modify2") m["bla"] = ["1234", "456"] @@ -229,7 +229,7 @@ class SimpleLdb(unittest.TestCase): l.delete(ldb.Dn(l, "dc=modify2")) def test_transaction_commit(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") l.transaction_start() m = ldb.Message(ldb.Dn(l, "dc=foo")) m["foo"] = ["bar"] @@ -238,7 +238,7 @@ class SimpleLdb(unittest.TestCase): l.delete(m.dn) def test_transaction_cancel(self): - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") l.transaction_start() m = ldb.Message(ldb.Dn(l, "dc=foo")) m["foo"] = ["bar"] @@ -249,13 +249,13 @@ class SimpleLdb(unittest.TestCase): def test_set_debug(self): def my_report_fn(level, text): pass - l = ldb.Ldb("foo.tdb") + l = ldb.Ldb("foo.ldb") l.set_debug(my_report_fn) class DnTests(unittest.TestCase): def setUp(self): - self.ldb = ldb.Ldb("foo.tdb") + self.ldb = ldb.Ldb("foo.ldb") def test_eq_str(self): x = ldb.Dn(self.ldb, "dc=foo,bar=bloe") @@ -402,7 +402,7 @@ class LdbMsgTests(unittest.TestCase): self.assertEquals(["dn", "foo", "bar"], self.msg.keys()) def test_dn(self): - self.msg.dn = ldb.Dn(ldb.Ldb("foo.tdb"), "@BASEINFO") + self.msg.dn = ldb.Dn(ldb.Ldb("foo.ldb"), "@BASEINFO") self.assertEquals("@BASEINFO", self.msg.dn.__str__()) def test_get_dn(self): -- cgit