summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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()