summaryrefslogtreecommitdiff
path: root/lib/ldb/tests/python
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2011-11-10 20:20:00 +0100
committerJelmer Vernooij <jelmer@samba.org>2011-11-10 23:37:04 +0100
commita0ed2da1053a15f2b453556952390968d86fa2f2 (patch)
tree3c5712c88c60ac4bf6e79471c9fbcf015a576310 /lib/ldb/tests/python
parentad40581142ca1e26406b0048b78d43ce54a5a2ff (diff)
downloadsamba-a0ed2da1053a15f2b453556952390968d86fa2f2.tar.gz
samba-a0ed2da1053a15f2b453556952390968d86fa2f2.tar.bz2
samba-a0ed2da1053a15f2b453556952390968d86fa2f2.zip
ldb: Re-apply pyldb fixes from Tridge and Amity, using unittest rather
than samba.tests.
Diffstat (limited to 'lib/ldb/tests/python')
-rwxr-xr-xlib/ldb/tests/python/api.py70
1 files changed, 37 insertions, 33 deletions
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
index 6a8df25b7b..97dd020ea5 100755
--- a/lib/ldb/tests/python/api.py
+++ b/lib/ldb/tests/python/api.py
@@ -3,7 +3,7 @@
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
import os
-import unittest
+from unittest import TestCase
import ldb
@@ -16,7 +16,8 @@ def filename():
dir_prefix = None
return tempfile.mktemp(dir=dir_prefix)
-class NoContextTests(unittest.TestCase):
+
+class NoContextTests(TestCase):
def test_valid_attr_name(self):
self.assertTrue(ldb.valid_attr_name("foo"))
@@ -31,11 +32,11 @@ class NoContextTests(unittest.TestCase):
self.assertEquals(1195499412, ldb.string_to_time("20071119191012.0Z"))
def test_binary_encode(self):
- encoded = self.binary_encode('test\\x')
- decoded = self.binary_decode(encoded)
+ encoded = ldb.binary_encode('test\\x')
+ decoded = ldb.binary_decode(encoded)
self.assertEquals(decoded, 'test\\x')
-class SimpleLdb(unittest.TestCase):
+class SimpleLdb(TestCase):
def test_connect(self):
ldb.Ldb(filename())
@@ -55,10 +56,6 @@ class SimpleLdb(unittest.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())
@@ -69,11 +66,11 @@ class SimpleLdb(unittest.TestCase):
def test_search(self):
l = ldb.Ldb(filename())
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 0)
def test_search_controls(self):
l = ldb.Ldb(filename())
- self.assertEquals(len(l.search(controls=["paged_results:0:5"])), 1)
+ self.assertEquals(len(l.search(controls=["paged_results:0:5"])), 0)
def test_search_attrs(self):
l = ldb.Ldb(filename())
@@ -146,10 +143,10 @@ class SimpleLdb(unittest.TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo4")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 0)
l.add(m)
try:
- self.assertEquals(len(l.search()), 2)
+ self.assertEquals(len(l.search()), 1)
finally:
l.delete(ldb.Dn(l, "dc=foo4"))
@@ -158,27 +155,27 @@ class SimpleLdb(unittest.TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo4")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 0)
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()), 1)
+ self.assertEquals(len(l.search()), 0)
l.add(m)
try:
- self.assertEquals(len(l.search()), 2)
+ self.assertEquals(len(l.search()), 1)
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()), 1)
+ self.assertEquals(len(l.search()), 0)
l.add(m)
try:
- self.assertEquals(len(l.search()), 2)
+ self.assertEquals(len(l.search()), 1)
finally:
l.delete(ldb.Dn(l, "dc=foo6"))
@@ -187,11 +184,11 @@ class SimpleLdb(unittest.TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo7")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 0)
l.add(m)
try:
l.rename(ldb.Dn(l, "dc=foo7"), ldb.Dn(l, "dc=bar"))
- self.assertEquals(len(l.search()), 2)
+ self.assertEquals(len(l.search()), 1)
finally:
l.delete(ldb.Dn(l, "dc=bar"))
@@ -200,12 +197,12 @@ class SimpleLdb(unittest.TestCase):
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=foo8")
m["bla"] = "bla"
- self.assertEquals(len(l.search()), 1)
+ self.assertEquals(len(l.search()), 0)
l.add(m)
- self.assertEquals(len(l.search()), 2)
+ self.assertEquals(len(l.search()), 1)
try:
l.rename("dc=foo8", "dc=bar")
- self.assertEquals(len(l.search()), 2)
+ self.assertEquals(len(l.search()), 1)
finally:
l.delete(ldb.Dn(l, "dc=bar"))
@@ -336,9 +333,10 @@ class SimpleLdb(unittest.TestCase):
self.assertRaises(ldb.LdbError,lambda: l.search("", ldb.SCOPE_SUBTREE, "&(dc=*)(dn=*)", ["dc"]))
-class DnTests(unittest.TestCase):
+class DnTests(TestCase):
def setUp(self):
+ super(DnTests, self).setUp()
self.ldb = ldb.Ldb(filename())
def test_set_dn_invalid(self):
@@ -454,9 +452,10 @@ class DnTests(unittest.TestCase):
self.assertFalse(dn3.is_child_of(dn2))
self.assertFalse(dn1.is_child_of(dn4))
-class LdbMsgTests(unittest.TestCase):
+class LdbMsgTests(TestCase):
def setUp(self):
+ super(LdbMsgTests, self).setUp()
self.msg = ldb.Message()
def test_init_dn(self):
@@ -531,10 +530,12 @@ class LdbMsgTests(unittest.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"))
-
+ self.assertEquals(None, self.msg.get("tatayoyo", idx=0))
self.assertEquals("anniecordie", self.msg.get("tatayoyo", "anniecordie"))
def test_get_unknown(self):
@@ -588,7 +589,7 @@ class LdbMsgTests(unittest.TestCase):
-class MessageElementTests(unittest.TestCase):
+class MessageElementTests(TestCase):
def test_cmp_element(self):
x = ldb.MessageElement(["foo"])
@@ -633,7 +634,7 @@ class MessageElementTests(unittest.TestCase):
self.assertEquals("MessageElement(['456'])", repr(el))
-class ModuleTests(unittest.TestCase):
+class ModuleTests(TestCase):
def test_register_module(self):
class ExampleModule:
@@ -652,8 +653,8 @@ class ModuleTests(unittest.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,9 +666,10 @@ class ModuleTests(unittest.TestCase):
l = ldb.Ldb(name)
self.assertEquals(["init"], ops)
-class LdbResultTests(unittest.TestCase):
+class LdbResultTests(TestCase):
def setUp(self):
+ super(LdbResultTests, self).setUp()
name = filename()
self.name = name
if os.path.exists(name):
@@ -688,6 +690,7 @@ class LdbResultTests(unittest.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)
@@ -753,7 +756,8 @@ class LdbResultTests(unittest.TestCase):
found = True
self.assertTrue(found)
-class VersionTests(unittest.TestCase):
+
+class VersionTests(TestCase):
def test_version(self):
self.assertTrue(isinstance(ldb.__version__, str))