1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

ldb:tests: make api_base module

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Douglas Bagnall 2024-08-17 14:35:48 +12:00 committed by Andreas Schneider
parent 16820c883d
commit 6e947a20ee
2 changed files with 54 additions and 38 deletions

View File

@ -12,25 +12,12 @@ 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)
from api_base import (
MDB_PREFIX,
MDB_INDEX_OBJ,
tempdir,
LdbBaseTest
)
class NoContextTests(TestCase):
@ -74,25 +61,6 @@ class NoContextTests(TestCase):
self.assertEqual(encoded2, encoded)
class LdbBaseTest(TestCase):
def setUp(self):
super().setUp()
try:
if self.prefix is None:
self.prefix = TDB_PREFIX
except AttributeError:
self.prefix = TDB_PREFIX
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):

View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
# Simple tests for the ldb python bindings.
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
import os
from unittest import TestCase
import sys
sys.path.insert(0, "bin/python")
import ldb
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 LdbBaseTest(TestCase):
def setUp(self):
super().setUp()
try:
if self.prefix is None:
self.prefix = TDB_PREFIX
except AttributeError:
self.prefix = TDB_PREFIX
def url(self):
return self.prefix + self.filename
def flags(self):
if self.prefix == MDB_PREFIX:
return ldb.FLG_NOSYNC
else:
return 0