summaryrefslogtreecommitdiff
path: root/lib/ldb/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2011-11-10 13:40:03 +0100
committerJelmer Vernooij <jelmer@samba.org>2011-11-10 23:37:04 +0100
commit04be49f60091b54f6ab7cf2920b590b3f758ca81 (patch)
tree3d2e959f052621d2abbb7ed7d89b2777dbfbfb3a /lib/ldb/tests
parent4cafcf0e6b2eaeda01fc340cdf1e552bafc4073b (diff)
downloadsamba-04be49f60091b54f6ab7cf2920b590b3f758ca81.tar.gz
samba-04be49f60091b54f6ab7cf2920b590b3f758ca81.tar.bz2
samba-04be49f60091b54f6ab7cf2920b590b3f758ca81.zip
Revert "pyldb: fixed ldb API test"
This reverts commit 333248f08c83cc5b18f8e7e84cb19d79a8309d6e. This commit made the pyldb tests depend on the Samba testsuite.
Diffstat (limited to 'lib/ldb/tests')
-rwxr-xr-xlib/ldb/tests/python/api.py75
1 files changed, 39 insertions, 36 deletions
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
index 4a582beb25..6a8df25b7b 100755
--- a/lib/ldb/tests/python/api.py
+++ b/lib/ldb/tests/python/api.py
@@ -2,8 +2,8 @@
# Simple tests for the ldb python bindings.
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
-import os, sys
-from samba.tests import TestCase, TestSkipped
+import os
+import unittest
import ldb
@@ -16,7 +16,7 @@ def filename():
dir_prefix = None
return tempfile.mktemp(dir=dir_prefix)
-class NoContextTests(TestCase):
+class NoContextTests(unittest.TestCase):
def test_valid_attr_name(self):
self.assertTrue(ldb.valid_attr_name("foo"))
@@ -31,11 +31,11 @@ class NoContextTests(TestCase):
self.assertEquals(1195499412, ldb.string_to_time("20071119191012.0Z"))
def test_binary_encode(self):
- encoded = ldb.binary_encode('test\\x')
- decoded = ldb.binary_decode(encoded)
+ encoded = self.binary_encode('test\\x')
+ decoded = self.binary_decode(encoded)
self.assertEquals(decoded, 'test\\x')
-class SimpleLdb(TestCase):
+class SimpleLdb(unittest.TestCase):
def test_connect(self):
ldb.Ldb(filename())
@@ -55,6 +55,10 @@ class SimpleLdb(TestCase):
x = ldb.Ldb()
x.set_create_perms(0600)
+ def test_set_modules_dir(self):
+ x = ldb.Ldb()
+ x.set_modules_dir("/tmp")
+
def test_modules_none(self):
x = ldb.Ldb()
self.assertEquals([], x.modules())
@@ -65,11 +69,11 @@ class SimpleLdb(TestCase):
def test_search(self):
l = ldb.Ldb(filename())
- self.assertEquals(len(l.search()), 0)
+ self.assertEquals(len(l.search()), 1)
def test_search_controls(self):
l = ldb.Ldb(filename())
- self.assertEquals(len(l.search(controls=["paged_results:0:5"])), 0)
+ self.assertEquals(len(l.search(controls=["paged_results:0:5"])), 1)
def test_search_attrs(self):
l = ldb.Ldb(filename())
@@ -142,10 +146,10 @@ class SimpleLdb(TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo4")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 0)
+ self.assertEquals(len(l.search()), 1)
l.add(m)
try:
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 2)
finally:
l.delete(ldb.Dn(l, "dc=foo4"))
@@ -154,27 +158,27 @@ class SimpleLdb(TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo4")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 0)
+ self.assertEquals(len(l.search()), 1)
self.assertRaises(ldb.LdbError, lambda: l.add(m,["search_options:1:2"]))
def test_add_dict(self):
l = ldb.Ldb(filename())
m = {"dn": ldb.Dn(l, "dc=foo5"),
"bla": "bla"}
- self.assertEquals(len(l.search()), 0)
+ self.assertEquals(len(l.search()), 1)
l.add(m)
try:
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 2)
finally:
l.delete(ldb.Dn(l, "dc=foo5"))
def test_add_dict_string_dn(self):
l = ldb.Ldb(filename())
m = {"dn": "dc=foo6", "bla": "bla"}
- self.assertEquals(len(l.search()), 0)
+ self.assertEquals(len(l.search()), 1)
l.add(m)
try:
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 2)
finally:
l.delete(ldb.Dn(l, "dc=foo6"))
@@ -183,11 +187,11 @@ class SimpleLdb(TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo7")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 0)
+ self.assertEquals(len(l.search()), 1)
l.add(m)
try:
l.rename(ldb.Dn(l, "dc=foo7"), ldb.Dn(l, "dc=bar"))
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 2)
finally:
l.delete(ldb.Dn(l, "dc=bar"))
@@ -196,12 +200,12 @@ class SimpleLdb(TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo8")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 0)
- l.add(m)
self.assertEquals(len(l.search()), 1)
+ l.add(m)
+ self.assertEquals(len(l.search()), 2)
try:
l.rename("dc=foo8", "dc=bar")
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 2)
finally:
l.delete(ldb.Dn(l, "dc=bar"))
@@ -332,10 +336,9 @@ class SimpleLdb(TestCase):
self.assertRaises(ldb.LdbError,lambda: l.search("", ldb.SCOPE_SUBTREE, "&(dc=*)(dn=*)", ["dc"]))
-class DnTests(TestCase):
+class DnTests(unittest.TestCase):
def setUp(self):
- super(DnTests, self).setUp()
self.ldb = ldb.Ldb(filename())
def test_set_dn_invalid(self):
@@ -451,10 +454,9 @@ class DnTests(TestCase):
self.assertFalse(dn3.is_child_of(dn2))
self.assertFalse(dn1.is_child_of(dn4))
-class LdbMsgTests(TestCase):
+class LdbMsgTests(unittest.TestCase):
def setUp(self):
- super(LdbMsgTests, self).setUp()
self.msg = ldb.Message()
def test_init_dn(self):
@@ -529,12 +531,10 @@ class LdbMsgTests(TestCase):
def test_get_other(self):
self.msg["foo"] = ["bar"]
self.assertEquals("bar", self.msg.get("foo")[0])
- self.assertEquals("bar", self.msg.get("foo", idx=0))
- self.assertEquals(None, self.msg.get("foo", idx=1))
- self.assertEquals("", self.msg.get("foo", default='', idx=1))
def test_get_default(self):
- self.assertEquals(None, self.msg.get("tatayoyo", idx=0))
+ self.assertEquals(None, self.msg.get("tatayoyo"))
+
self.assertEquals("anniecordie", self.msg.get("tatayoyo", "anniecordie"))
def test_get_unknown(self):
@@ -588,7 +588,7 @@ class LdbMsgTests(TestCase):
-class MessageElementTests(TestCase):
+class MessageElementTests(unittest.TestCase):
def test_cmp_element(self):
x = ldb.MessageElement(["foo"])
@@ -633,7 +633,7 @@ class MessageElementTests(TestCase):
self.assertEquals("MessageElement(['456'])", repr(el))
-class ModuleTests(TestCase):
+class ModuleTests(unittest.TestCase):
def test_register_module(self):
class ExampleModule:
@@ -652,8 +652,8 @@ class ModuleTests(TestCase):
def search(self, *args, **kwargs):
return self.next.search(*args, **kwargs)
- def request(self, *args, **kwargs):
- pass
+ def request(self, *args, **kwargs):
+ pass
name = filename()
ldb.register_module(ExampleModule)
@@ -665,10 +665,9 @@ class ModuleTests(TestCase):
l = ldb.Ldb(name)
self.assertEquals(["init"], ops)
-class LdbResultTests(TestCase):
+class LdbResultTests(unittest.TestCase):
def setUp(self):
- super(LdbResultTests, self).setUp()
name = filename()
self.name = name
if os.path.exists(name):
@@ -689,7 +688,6 @@ class LdbResultTests(TestCase):
self.l.add({"dn": "OU=OU10,DC=SAMBA,DC=ORG", "name": "OU #10"})
def tearDown(self):
- super(LdbResultTests, self).tearDown()
if os.path.exists(self.name):
os.unlink(self.name)
@@ -755,7 +753,12 @@ class LdbResultTests(TestCase):
found = True
self.assertTrue(found)
-class VersionTests(TestCase):
+class VersionTests(unittest.TestCase):
def test_version(self):
self.assertTrue(isinstance(ldb.__version__, str))
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.TestProgram()