From acae07bc17d3e8dbafa5667711d25616f99a91a9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 19 Sep 2008 16:17:52 +0200 Subject: Add support for implementing LDB modules in Python. --- source4/lib/ldb/tests/python/api.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/tests/python') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 99ad1a9e66..bc3bbc1c8c 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -48,6 +48,14 @@ class SimpleLdb(unittest.TestCase): x = ldb.Ldb() x.set_modules_dir("/tmp") + def test_modules_none(self): + x = ldb.Ldb() + self.assertEquals([], x.modules()) + + def test_modules_tdb(self): + x = ldb.Ldb("bar.ldb") + self.assertEquals("[]", repr(x.modules())) + def test_search(self): l = ldb.Ldb("foo.ldb") self.assertEquals(len(l.search()), 1) @@ -451,12 +459,27 @@ class MessageElementTests(unittest.TestCase): x = ldb.MessageElement(["foo"]) self.assertEquals("foo", x) -class ExampleModule: - name = "example" - class ModuleTests(unittest.TestCase): def test_register_module(self): - ldb.register_module(ExampleModule()) + class ExampleModule: + name = "example" + ldb.register_module(ExampleModule) + + def test_use_module(self): + ops = [] + class ExampleModule: + name = "bla" + + def __init__(self, ldb, next): + ops.append("init") + + ldb.register_module(ExampleModule) + l = ldb.Ldb("usemodule.ldb") + l.add({"dn": "@MODULES", + "@LIST": "bla"}) + self.assertEquals([], ops) + l = ldb.Ldb("usemodule.ldb") + self.assertEquals(["init"], ops) if __name__ == '__main__': import unittest -- cgit From 0e2928f94651c53d653a3ad83bbda5608b4d4c24 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 20 Sep 2008 15:06:26 +0200 Subject: Don't expose ldb_request in the Python API but rather use regular parameters. --- source4/lib/ldb/tests/python/api.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tests/python') diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index bc3bbc1c8c..4b3501839f 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -2,7 +2,7 @@ # Simple tests for the ldb python bindings. # Copyright (C) 2007 Jelmer Vernooij -import sys +import os, sys import unittest # Required for the standalone LDB build @@ -472,11 +472,16 @@ class ModuleTests(unittest.TestCase): def __init__(self, ldb, next): ops.append("init") + self.next = next + + def search(self, *args, **kwargs): + return self.next.search(*args, **kwargs) ldb.register_module(ExampleModule) + if os.path.exists("usemodule.ldb"): + os.unlink("usemodule.ldb") l = ldb.Ldb("usemodule.ldb") - l.add({"dn": "@MODULES", - "@LIST": "bla"}) + l.add({"dn": "@MODULES", "@LIST": "bla"}) self.assertEquals([], ops) l = ldb.Ldb("usemodule.ldb") self.assertEquals(["init"], ops) -- cgit From 7b20cbb1152af7f3779cbb0dd74d939d8f1637c0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 24 Sep 2008 01:34:10 -0400 Subject: Fix python test, we can't check only the first member, because the order is not guaranteed --- source4/lib/ldb/tests/python/ldap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tests/python') diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py index bc6f80e856..6c910b63f1 100755 --- a/source4/lib/ldb/tests/python/ldap.py +++ b/source4/lib/ldb/tests/python/ldap.py @@ -781,7 +781,10 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """ self.assertTrue("objectGuid" not in res[0]) self.assertTrue("whenCreated" in res[0]) self.assertTrue("nTSecurityDescriptor" in res[0]) - self.assertEquals(res[0]["member"][0].upper(), ("CN=ldaptestuser2,CN=Users," + self.base_dn).upper()) + memberUP = [] + for m in res[0]["member"]: + memberUP.append(m.upper()) + self.assertTrue(("CN=ldaptestuser2,CN=Users," + self.base_dn).upper() in memberUP) ldb.modify_ldif(""" dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ -- cgit From f8a02a1a804fdb8640989595e2b57df86281c0f7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 8 Oct 2008 03:33:38 +0200 Subject: Fix subunit files location after cherrypicks. --- source4/lib/ldb/tests/python/ldap.py | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tests/python') diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py index 6c910b63f1..e2cc658521 100755 --- a/source4/lib/ldb/tests/python/ldap.py +++ b/source4/lib/ldb/tests/python/ldap.py @@ -8,6 +8,7 @@ import sys import time sys.path.append("bin/python") +sys.path.append("../lib/subunit/python") import samba.getopt as options -- cgit