[SCM] Samba Shared Repository - branch master updated

Andreas Schneider asn at samba.org
Tue Sep 24 10:39:02 UTC 2024


The branch, master has been updated
       via  3d47fc749ae ldb:test:api_search: shift remaining setUp adds to class add_index
       via  45137017af3 ldb:test:api_search: remove pass-through setUp()s
       via  1871eb9d1cb ldb:test:api_search: use @unittest.skipIf for LMDB tests
       via  235c7d15ef5 ldb:test:api_search: skip LMDB tests at class level
       via  d9225d2460e ldb:test:api_search: use class method to add index
       via  f7269c2fa36 ldb:test:api_search: tidy up files in each subclass
       via  2029cd7a7b9 ldb:test:api_search: set up the database once and use copies
       via  98d408be865 ldb:test:api_search: use test name as db name
       via  146540a1286 ldb:test:api_search: put config options on class, not instance.
       via  69a00fd0d77 ldb:test:api_search: improve attribute access tests
       via  b08427d086c ldb:test:api_base: make flags method a class method
       via  8d97ce958fe ldb:test:api_base: simplify prefix selection
       via  83f3afaac42 ldb:tests:index: use abi_base
       via  0c968d374aa ldb:tests:crash: rationalise imports
       via  102660e7d19 ldb:tests:api_simple uses conventional 4 space indent
       via  b932143c8d5 ldb:tests:repack: use common api_base variables
       via  ccc732dae29 ldb:tests:api_misc: fix Control test
       via  c706021d551 ldb:tests: move api.py to api_misc
       via  081125f3b31 ldb:tests: make api_simple module
       via  565eba4120b ldb:tests: make api_add_modify module
       via  e4410ada212 ldb:tests: make api_search module
       via  6e947a20ee4 ldb:tests: make api_base module
       via  16820c883d1 ldb:tests:api.py uses .disconnect before rmdir
       via  09d9680f5ee ldb:pytest:api: remove unnecessary super() parameters
       via  b1fd6e2b073 ldb:pytest:api: remove pass-though tearDowns
       via  64e3c5cba96 ldb:py bindings: ldb.Ldb().__str__ prints connection URL
      from  25a222225db ctdb: Use str_list_add_printf() in lock_helper_args()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 3d47fc749aef6822f11036ae3f93d11886c4f9bc
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Aug 29 12:52:13 2024 +1200

    ldb:test:api_search: shift remaining setUp adds to class add_index
    
    Before:
    
    ldb.python.api_search -> 52
    ldb.python.api_search.tr -> 48
    
    After:
    
    ldb.python.api_search.tr -> 10
    ldb.python.api_search -> 9
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Tue Sep 24 10:38:03 UTC 2024 on atb-devel-224

commit 45137017af3860be31f974c711e96efa95d6b61c
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Aug 29 12:39:09 2024 +1200

    ldb:test:api_search: remove pass-through setUp()s
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 1871eb9d1cbc94c2a429f7db630e4b124f49a0ed
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Aug 29 12:38:27 2024 +1200

    ldb:test:api_search: use @unittest.skipIf for LMDB tests
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 235c7d15ef516685d86763229fed7803805ad272
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Aug 29 12:23:55 2024 +1200

    ldb:test:api_search: skip LMDB tests at class level
    
    LMDB is not going to turn up midway through the testsuite, so we might
    as well skip the whole class
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit d9225d2460eb5887c6a16b5443c4f33d3c208aee
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sun Aug 18 11:03:54 2024 +1200

    ldb:test:api_search: use class method to add index
    
    The index attribute of these classes was a mutable object, which made
    me nervous. If a subclass were to alter the class.index (rather than
    replace it), it would affect tests in other subclasses.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit f7269c2fa364aaa6a46d75f1df584d333ba7d13e
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Aug 29 11:05:28 2024 +1200

    ldb:test:api_search: tidy up files in each subclass
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 2029cd7a7b962749607e65c0cdd20d0e4c7bb206
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 20:21:36 2024 +1200

    ldb:test:api_search: set up the database once and use copies
    
    The api_search tests are really slow, in part because we populate the
    database identically for all the individual tests. We can instead do
    it once and use copies.
    
    This makes the test several times faster.
    Comparing "make test TESTS=ldb.python":
    
    Before:
    
    TOP 10 slowest tests
    ldb.python.api_search.tr -> 415
    ldb.python.api_search -> 413
    ldb.python.api_add_modify -> 5
    ldb.python.api_add_modify.tr -> 4
    ldb.python.index.tr -> 4
    ldb.python.index -> 4
    ldb.python.api_simple.tr -> 2
    ldb.python.api_simple -> 2
    ldb.python.repack -> 2
    ldb.python.api_misc.tr -> 1
    'testonly' finished successfully (14m13.276s)
    
    After:
    
    TOP 10 slowest tests
    ldb.python.api_search.tr -> 52
    ldb.python.api_search -> 50
    ldb.python.api_add_modify -> 7
    ldb.python.api_add_modify.tr -> 7
    ldb.python.index.tr -> 4
    ldb.python.index -> 4
    ldb.python.api_simple -> 4
    ldb.python.api_simple.tr -> 2
    ldb.python.repack -> 2
    ldb.python.api_misc -> 1
    'testonly' finished successfully (2m14.505s)
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 98d408be8657c3e201141369a069a3e086f805b2
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Aug 29 10:56:38 2024 +1200

    ldb:test:api_search: use test name as db name
    
    This will help enusre we are using the right DB when (in the next
    commit) we set up the database for each test via copy. It also helps
    with debugging.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 146540a12867a50a3c2eca9752bdf8789d5dd5f0
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 20:47:39 2024 +1200

    ldb:test:api_search: put config options on class, not instance.
    
    This makes them available to class methods.
    
    In a later commit we will convert the index attribute into an
    add_index() class method, because having a mutable variable on a class
    is a slightly bad idea.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 69a00fd0d770c9fd3f45c5b43514c2acc8f927ce
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 20:18:02 2024 +1200

    ldb:test:api_search: improve attribute access tests
    
    `list = res.msgs` tests nothing more than a bare `res.msgs`,
    and we can instead assert that the result is a list.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit b08427d086ce3d4e9fd1bda9ed69cd367ee18904
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 20:49:23 2024 +1200

    ldb:test:api_base: make flags method a class method
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 8d97ce958fe8328d2f3c365d73fc440142c353bb
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 20:12:11 2024 +1200

    ldb:test:api_base: simplify prefix selection
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 83f3afaac42ff7d2606c380b59c94f55b377fae0
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 18:13:00 2024 +1200

    ldb:tests:index: use abi_base
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 0c968d374aa9c621a4df937f5f09d0c27d5b689c
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 18:10:33 2024 +1200

    ldb:tests:crash: rationalise imports
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 102660e7d1975f9cc3bd4c3984eae9306d03acc4
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 18:10:02 2024 +1200

    ldb:tests:api_simple uses conventional 4 space indent
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit b932143c8d56cfc6bbfff47f7db585540378671b
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 18:09:11 2024 +1200

    ldb:tests:repack: use common api_base variables
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit ccc732dae294351e7c5caeb779be70e7afbf6139
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 18:08:09 2024 +1200

    ldb:tests:api_misc: fix Control test
    
    `self.assertRaises(TypeError, ldb.Control, ldb, 1234)` is raising a
    TypeError because `ldb` is not an ldb.Ldb object, it is the ldb module.
    
    What we want to test here is that the non-string `1234` raises a
    TypeError -- the previous line tests the type of the ldb argument.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit c706021d551f1bc9b1e09b7109cb9bfa50d18c2d
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 14:48:57 2024 +1200

    ldb:tests: move api.py to api_misc
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 081125f3b319ca8807f0f4d9b5f279ab4dacced5
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 14:46:05 2024 +1200

    ldb:tests: make api_simple module
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 565eba4120bccbd0a50ccb04653d6b386315f676
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 14:42:24 2024 +1200

    ldb:tests: make api_add_modify module
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit e4410ada21292a5652228d1b692a1aeb38d182c8
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 14:41:18 2024 +1200

    ldb:tests: make api_search module
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 6e947a20ee4a2a30aa63c5cea135fa34d94e330c
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 14:35:48 2024 +1200

    ldb:tests: make api_base module
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 16820c883d19572c0e25e84de4d408f2f3e16421
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Sat Aug 17 13:27:52 2024 +1200

    ldb:tests:api.py uses .disconnect before rmdir
    
    super.tearDown() was removing the tmpdir, but because self.ldb had
    the file open, the directory was not cleared.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 09d9680f5ee25cd8db7903a2ca0a60c492b4b6cc
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Aug 16 14:21:20 2024 +1200

    ldb:pytest:api: remove unnecessary super() parameters
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit b1fd6e2b07360a631ac123a595c454474f985058
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Aug 16 14:06:53 2024 +1200

    ldb:pytest:api: remove pass-though tearDowns
    
    The result is exactly the same, unless we previously had the wrong
    class name in the pass-through, in which case the result is *probably*
    the same, only more correct.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 64e3c5cba965fa8b0625a7165b98610418518818
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Mon Aug 19 12:19:22 2024 +1200

    ldb:py bindings: ldb.Ldb().__str__ prints connection URL
    
    before:  "<ldb connection>"
    after:   "<ldb connection tdb:///path/to/samdb.ldb>"
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/ldb/pyldb.c                        |    7 +-
 lib/ldb/tests/python/api.py            | 3912 --------------------------------
 lib/ldb/tests/python/api_add_modify.py |  376 +++
 lib/ldb/tests/python/api_base.py       |   43 +
 lib/ldb/tests/python/api_misc.py       | 1047 +++++++++
 lib/ldb/tests/python/api_search.py     | 1741 ++++++++++++++
 lib/ldb/tests/python/api_simple.py     |  752 ++++++
 lib/ldb/tests/python/crash.py          |    3 +-
 lib/ldb/tests/python/index.py          |   18 +-
 lib/ldb/tests/python/repack.py         |   17 +-
 selftest/tests.py                      |   35 +-
 11 files changed, 4009 insertions(+), 3942 deletions(-)
 delete mode 100755 lib/ldb/tests/python/api.py
 create mode 100644 lib/ldb/tests/python/api_add_modify.py
 create mode 100644 lib/ldb/tests/python/api_base.py
 create mode 100644 lib/ldb/tests/python/api_misc.py
 create mode 100644 lib/ldb/tests/python/api_search.py
 create mode 100644 lib/ldb/tests/python/api_simple.py


Changeset truncated at 500 lines:

diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 53b855990bb..bf433288206 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -1342,7 +1342,12 @@ static PyObject *py_ldb_setup_wellknown_attributes(PyLdbObject *self,
 
 static PyObject *py_ldb_repr(PyLdbObject *self)
 {
-	return PyUnicode_FromString("<ldb connection>");
+	struct ldb_context *ldb_ctx = pyldb_Ldb_AS_LDBCONTEXT(self);
+	const char *url = ldb_get_opaque(ldb_ctx, "ldb_url");
+	if (url == NULL) {
+		url = "no connection";
+	}
+	return PyUnicode_FromFormat("<ldb connection %s>", url);
 }
 
 static PyObject *py_ldb_get_root_basedn(PyLdbObject *self,
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
deleted file mode 100755
index bdd69f07734..00000000000
--- a/lib/ldb/tests/python/api.py
+++ /dev/null
@@ -1,3912 +0,0 @@
-#!/usr/bin/env python3
-# Simple tests for the ldb python bindings.
-# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
-
-import os
-from unittest import TestCase
-import sys
-sys.path.insert(0, "bin/python")
-import gc
-import time
-import ldb
-import shutil
-import errno
-
-
-TDB_PREFIX = "tdb://"
-MDB_PREFIX = "mdb://"
-
-MDB_INDEX_OBJ = {
-    "dn": "@INDEXLIST",
-    "@IDXONE": [b"1"],
-    "@IDXGUID": [b"objectUUID"],
-    "@IDX_DN_GUID": [b"GUID"]
-}
-
-
-def tempdir():
-    import tempfile
-    try:
-        dir_prefix = os.path.join(os.environ["SELFTEST_PREFIX"], "tmp")
-    except KeyError:
-        dir_prefix = None
-    return tempfile.mkdtemp(dir=dir_prefix)
-
-
-class NoContextTests(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.assertEqual("19700101000000.0Z", ldb.timestring(0))
-        self.assertEqual("20071119191012.0Z", ldb.timestring(1195499412))
-
-        self.assertEqual("00000101000000.0Z", ldb.timestring(-62167219200))
-        self.assertEqual("99991231235959.0Z", ldb.timestring(253402300799))
-
-        # should result with OSError EOVERFLOW from gmtime()
-        with self.assertRaises(OSError) as err:
-            ldb.timestring(-62167219201)
-        self.assertEqual(err.exception.errno, errno.EOVERFLOW)
-        with self.assertRaises(OSError) as err:
-            ldb.timestring(253402300800)
-        self.assertEqual(err.exception.errno, errno.EOVERFLOW)
-        with self.assertRaises(OSError) as err:
-            ldb.timestring(0x7fffffffffffffff)
-        self.assertEqual(err.exception.errno, errno.EOVERFLOW)
-
-    def test_string_to_time(self):
-        self.assertEqual(0, ldb.string_to_time("19700101000000.0Z"))
-        self.assertEqual(-1, ldb.string_to_time("19691231235959.0Z"))
-        self.assertEqual(1195499412, ldb.string_to_time("20071119191012.0Z"))
-
-        self.assertEqual(-62167219200, ldb.string_to_time("00000101000000.0Z"))
-        self.assertEqual(253402300799, ldb.string_to_time("99991231235959.0Z"))
-
-    def test_binary_encode(self):
-        encoded = ldb.binary_encode(b'test\\x')
-        decoded = ldb.binary_decode(encoded)
-        self.assertEqual(decoded, b'test\\x')
-
-        encoded2 = ldb.binary_encode('test\\x')
-        self.assertEqual(encoded2, encoded)
-
-
-class LdbBaseTest(TestCase):
-    def setUp(self):
-        super(LdbBaseTest, self).setUp()
-        try:
-            if self.prefix is None:
-                self.prefix = TDB_PREFIX
-        except AttributeError:
-            self.prefix = TDB_PREFIX
-
-    def tearDown(self):
-        super(LdbBaseTest, self).tearDown()
-
-    def url(self):
-        return self.prefix + self.filename
-
-    def flags(self):
-        if self.prefix == MDB_PREFIX:
-            return ldb.FLG_NOSYNC
-        else:
-            return 0
-
-
-class SimpleLdb(LdbBaseTest):
-
-    def setUp(self):
-        super(SimpleLdb, self).setUp()
-        self.testdir = tempdir()
-        self.filename = os.path.join(self.testdir, "test.ldb")
-        self.ldb = ldb.Ldb(self.url(), flags=self.flags())
-        try:
-            self.ldb.add(self.index)
-        except AttributeError:
-            pass
-
-    def tearDown(self):
-        shutil.rmtree(self.testdir)
-        super(SimpleLdb, self).tearDown()
-        # Ensure the LDB is closed now, so we close the FD
-        del(self.ldb)
-
-    def test_connect(self):
-        ldb.Ldb(self.url(), flags=self.flags())
-
-    def test_connect_none(self):
-        ldb.Ldb()
-
-    def test_connect_later(self):
-        x = ldb.Ldb()
-        x.connect(self.url(), flags=self.flags())
-
-    def test_connect_twice(self):
-        url = self.url()
-        x = ldb.Ldb(url)
-        with self.assertRaises(ldb.LdbError):
-            x.connect(url, flags=self.flags())
-
-    def test_connect_twice_later(self):
-        url = self.url()
-        flags = self.flags()
-        x = ldb.Ldb()
-        x.connect(url, flags)
-        with self.assertRaises(ldb.LdbError):
-            x.connect(url, flags)
-
-    def test_connect_and_disconnect(self):
-        url = self.url()
-        flags = self.flags()
-        x = ldb.Ldb()
-        x.connect(url, flags)
-        x.disconnect()
-        x.connect(url, flags)
-        x.disconnect()
-
-    def test_repr(self):
-        x = ldb.Ldb()
-        self.assertTrue(repr(x).startswith("<ldb connection"))
-
-    def test_set_create_perms(self):
-        x = ldb.Ldb()
-        x.set_create_perms(0o600)
-
-    def test_search(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(len(l.search()), 0)
-
-    def test_search_controls(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(len(l.search(controls=["paged_results:0:5"])), 0)
-
-    def test_utf8_ldb_Dn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        dn = ldb.Dn(l, (b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc').decode('utf8'))
-
-    def test_utf8_encoded_ldb_Dn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        dn_encoded_utf8 = b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc'
-        try:
-            dn = ldb.Dn(l, dn_encoded_utf8)
-        except UnicodeDecodeError as e:
-                raise
-        except TypeError as te:
-           p3errors = ["argument 2 must be str, not bytes",
-                       "Can't convert 'bytes' object to str implicitly"]
-           self.assertIn(str(te), p3errors)
-
-    def test_search_attrs(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0)
-
-    def test_search_string_dn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(len(l.search("", ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0)
-
-    def test_search_attr_string(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertRaises(TypeError, l.search, attrs="dc")
-        self.assertRaises(TypeError, l.search, attrs=b"dc")
-
-    def test_opaque(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        l.set_opaque("my_opaque", True)
-        self.assertTrue(l.get_opaque("my_opaque") is not None)
-        self.assertEqual(None, l.get_opaque("unknown"))
-
-    def test_opaque_bool(self):
-        """Test that we can set boolean opaque values."""
-
-        db = ldb.Ldb(self.url(), flags=self.flags())
-        name = "my_opaque"
-
-        db.set_opaque(name, False)
-        self.assertEqual(False, db.get_opaque(name))
-
-        db.set_opaque(name, True)
-        self.assertEqual(True, db.get_opaque(name))
-
-    def test_opaque_int(self):
-        """Test that we can set (positive) integer opaque values."""
-
-        db = ldb.Ldb(self.url(), flags=self.flags())
-        name = "my_opaque"
-
-        db.set_opaque(name, 0)
-        self.assertEqual(0, db.get_opaque(name))
-
-        db.set_opaque(name, 12345678)
-        self.assertEqual(12345678, db.get_opaque(name))
-
-        # Negative values can’t be set.
-        self.assertRaises(OverflowError, db.set_opaque, name, -99999)
-
-    def test_opaque_string(self):
-        """Test that we can set string opaque values."""
-
-        db = ldb.Ldb(self.url(), flags=self.flags())
-        name = "my_opaque"
-
-        db.set_opaque(name, "")
-        self.assertEqual("", db.get_opaque(name))
-
-        db.set_opaque(name, "foo bar")
-        self.assertEqual("foo bar", db.get_opaque(name))
-
-    def test_opaque_none(self):
-        """Test that we can set an opaque to None to effectively unset it."""
-
-        db = ldb.Ldb(self.url(), flags=self.flags())
-        name = "my_opaque"
-
-        # An opaque that has not been set is the same as None.
-        self.assertIsNone(db.get_opaque(name))
-
-        # Give the opaque a value.
-        db.set_opaque(name, 3)
-        self.assertEqual(3, db.get_opaque(name))
-
-        # Test that we can set the opaque to None to unset it.
-        db.set_opaque(name, None)
-        self.assertIsNone(db.get_opaque(name))
-
-    def test_opaque_unsupported(self):
-        """Test that trying to set unsupported values raises an error."""
-
-        db = ldb.Ldb(self.url(), flags=self.flags())
-        name = "my_opaque"
-
-        self.assertRaises(ValueError, db.set_opaque, name, [])
-        self.assertRaises(ValueError, db.set_opaque, name, ())
-        self.assertRaises(ValueError, db.set_opaque, name, 3.14)
-        self.assertRaises(ValueError, db.set_opaque, name, 3+2j)
-        self.assertRaises(ValueError, db.set_opaque, name, b'foo')
-
-    def test_search_scope_base_empty_db(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(len(l.search(ldb.Dn(l, "dc=foo1"),
-                                      ldb.SCOPE_BASE)), 0)
-
-    def test_search_scope_onelevel_empty_db(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(len(l.search(ldb.Dn(l, "dc=foo1"),
-                                      ldb.SCOPE_ONELEVEL)), 0)
-
-    def test_delete(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertRaises(ldb.LdbError, lambda: l.delete(ldb.Dn(l, "dc=foo2")))
-
-    def test_delete_w_unhandled_ctrl(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        m = ldb.Message()
-        m.dn = ldb.Dn(l, "dc=foo1")
-        m["b"] = [b"a"]
-        m["objectUUID"] = b"0123456789abcdef"
-        l.add(m)
-        self.assertRaises(ldb.LdbError, lambda: l.delete(m.dn, ["search_options:1:2"]))
-        l.delete(m.dn)
-
-    def test_contains(self):
-        name = self.url()
-        l = ldb.Ldb(name, flags=self.flags())
-        self.assertFalse(ldb.Dn(l, "dc=foo3") in l)
-        l = ldb.Ldb(name, flags=self.flags())
-        m = ldb.Message()
-        m.dn = ldb.Dn(l, "dc=foo3")
-        m["b"] = ["a"]
-        m["objectUUID"] = b"0123456789abcdef"
-        l.add(m)
-        try:
-            self.assertTrue(ldb.Dn(l, "dc=foo3") in l)
-            self.assertFalse(ldb.Dn(l, "dc=foo4") in l)
-        finally:
-            l.delete(m.dn)
-
-    def test_get_config_basedn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(None, l.get_config_basedn())
-
-    def test_get_root_basedn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(None, l.get_root_basedn())
-
-    def test_get_schema_basedn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(None, l.get_schema_basedn())
-
-    def test_get_default_basedn(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual(None, l.get_default_basedn())
-
-    def test_add(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        m = ldb.Message()
-        m.dn = ldb.Dn(l, "dc=foo4")
-        m["bla"] = b"bla"
-        m["objectUUID"] = b"0123456789abcdef"
-        self.assertEqual(len(l.search()), 0)
-        l.add(m)
-        try:
-            self.assertEqual(len(l.search()), 1)
-        finally:
-            l.delete(ldb.Dn(l, "dc=foo4"))
-
-    def test_search_iterator(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        s = l.search_iterator()
-        s.abandon()
-        try:
-            for me in s:
-                self.fail()
-            self.fail()
-        except RuntimeError as re:
-            pass
-        try:
-            s.abandon()
-            self.fail()
-        except RuntimeError as re:
-            pass
-        try:
-            s.result()
-            self.fail()
-        except RuntimeError as re:
-            pass
-
-        s = l.search_iterator()
-        count = 0
-        for me in s:
-            self.assertTrue(isinstance(me, ldb.Message))
-            count += 1
-        r = s.result()
-        self.assertEqual(len(r), 0)
-        self.assertEqual(count, 0)
-
-        m1 = ldb.Message()
-        m1.dn = ldb.Dn(l, "dc=foo4")
-        m1["bla"] = b"bla"
-        m1["objectUUID"] = b"0123456789abcdef"
-        l.add(m1)
-        try:
-            s = l.search_iterator()
-            msgs = []
-            for me in s:
-                self.assertTrue(isinstance(me, ldb.Message))
-                count += 1
-                msgs.append(me)
-            r = s.result()
-            self.assertEqual(len(r), 0)
-            self.assertEqual(len(msgs), 1)
-            self.assertEqual(msgs[0].dn, m1.dn)
-
-            m2 = ldb.Message()
-            m2.dn = ldb.Dn(l, "dc=foo5")
-            m2["bla"] = b"bla"
-            m2["objectUUID"] = b"0123456789abcdee"
-            l.add(m2)
-
-            s = l.search_iterator()
-            msgs = []
-            for me in s:
-                self.assertTrue(isinstance(me, ldb.Message))
-                count += 1
-                msgs.append(me)
-            r = s.result()
-            self.assertEqual(len(r), 0)
-            self.assertEqual(len(msgs), 2)
-            if msgs[0].dn == m1.dn:
-                self.assertEqual(msgs[0].dn, m1.dn)
-                self.assertEqual(msgs[1].dn, m2.dn)
-            else:
-                self.assertEqual(msgs[0].dn, m2.dn)
-                self.assertEqual(msgs[1].dn, m1.dn)
-
-            s = l.search_iterator()
-            msgs = []
-            for me in s:
-                self.assertTrue(isinstance(me, ldb.Message))
-                count += 1
-                msgs.append(me)
-                break
-            try:
-                s.result()
-                self.fail()
-            except RuntimeError as re:
-                pass
-            for me in s:
-                self.assertTrue(isinstance(me, ldb.Message))
-                count += 1
-                msgs.append(me)
-                break
-            for me in s:
-                self.fail()
-
-            r = s.result()
-            self.assertEqual(len(r), 0)
-            self.assertEqual(len(msgs), 2)
-            if msgs[0].dn == m1.dn:
-                self.assertEqual(msgs[0].dn, m1.dn)
-                self.assertEqual(msgs[1].dn, m2.dn)
-            else:
-                self.assertEqual(msgs[0].dn, m2.dn)
-                self.assertEqual(msgs[1].dn, m1.dn)
-        finally:
-            l.delete(ldb.Dn(l, "dc=foo4"))
-            l.delete(ldb.Dn(l, "dc=foo5"))
-
-    def test_add_text(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        m = ldb.Message()
-        m.dn = ldb.Dn(l, "dc=foo4")
-        m["bla"] = "bla"
-        m["objectUUID"] = b"0123456789abcdef"
-        self.assertEqual(len(l.search()), 0)
-        l.add(m)
-        try:
-            self.assertEqual(len(l.search()), 1)
-        finally:
-            l.delete(ldb.Dn(l, "dc=foo4"))
-
-    def test_add_w_unhandled_ctrl(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        m = ldb.Message()
-        m.dn = ldb.Dn(l, "dc=foo4")
-        m["bla"] = b"bla"
-        self.assertEqual(len(l.search()), 0)
-        self.assertRaises(ldb.LdbError, lambda: l.add(m, ["search_options:1:2"]))
-
-    def test_add_dict(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        m = {"dn": ldb.Dn(l, "dc=foo5"),
-             "bla": b"bla",
-             "objectUUID": b"0123456789abcdef"}
-        self.assertEqual(len(l.search()), 0)
-        l.add(m)
-        try:
-            self.assertEqual(len(l.search()), 1)
-        finally:
-            l.delete(ldb.Dn(l, "dc=foo5"))
-
-    def test_add_dict_text(self):
-        l = ldb.Ldb(self.url(), flags=self.flags())
-        m = {"dn": ldb.Dn(l, "dc=foo5"),
-             "bla": "bla",


-- 
Samba Shared Repository



More information about the samba-cvs mailing list