Skip to content

Commit 4af1d54

Browse files
authored
Merge pull request #8 – Tests: Check for LDAP schema and slapd binaries
#8
2 parents b587fd6 + c3876a0 commit 4af1d54

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

Lib/slapdtest.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class SlapdObject(object):
115115
elif os.path.isdir("/etc/ldap/schema"):
116116
SCHEMADIR = "/etc/ldap/schema"
117117
else:
118-
PATH_SCHEMA_CORE = None
118+
SCHEMADIR = None
119119
PATH_LDAPADD = os.path.join(BINDIR, 'ldapadd')
120120
PATH_LDAPMODIFY = os.path.join(BINDIR, 'ldapmodify')
121121
PATH_LDAPWHOAMI = os.path.join(BINDIR, 'ldapwhoami')
@@ -138,6 +138,17 @@ def __init__(self):
138138
ldapi_path = os.path.join(self.testrundir, 'ldapi')
139139
self.ldapi_uri = "ldapi://%s" % quote_plus(ldapi_path)
140140

141+
def _check_requirements(self):
142+
binaries = [
143+
self.PATH_LDAPADD, self.PATH_LDAPMODIFY, self.PATH_LDAPWHOAMI,
144+
self.PATH_SLAPD, self.PATH_SLAPTEST
145+
]
146+
for binary in binaries:
147+
if not os.path.isfile(binary):
148+
raise ValueError('Binary {} is missing.'.format(binary))
149+
if self.SCHEMADIR is None:
150+
raise ValueError('SCHEMADIR is None, ldap schemas are missing.')
151+
141152
def setup_rundir(self):
142153
"""
143154
creates rundir structure
@@ -283,6 +294,7 @@ def start(self):
283294
"""
284295

285296
if self._proc is None:
297+
self._check_requirements()
286298
# prepare directory structure
287299
atexit.register(self.stop)
288300
self._cleanup_rundir()

Tests/t_bind.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
from slapdtest import SlapdObject
1414
from ldap.ldapobject import LDAPObject
1515

16-
server = None
17-
18-
1916
class TestBinds(unittest.TestCase):
2017

21-
def setUp(self):
22-
global server
23-
if server is None:
24-
server = SlapdObject()
25-
server.start()
18+
@classmethod
19+
def setUpClass(cls):
20+
cls.server = SlapdObject()
21+
cls.server.start()
22+
23+
cls.unicode_val = "abc\U0001f498def"
24+
cls.unicode_val_bytes = cls.unicode_val.encode('utf-8')
2625

27-
self.server = server
28-
self.unicode_val = "abc\U0001f498def"
29-
self.unicode_val_bytes = self.unicode_val.encode('utf-8')
26+
cls.dn_unicode = "CN=" + cls.unicode_val
27+
cls.dn_bytes = cls.dn_unicode.encode('utf-8')
3028

31-
self.dn_unicode = "CN=" + self.unicode_val
32-
self.dn_bytes = self.dn_unicode.encode('utf-8')
29+
@classmethod
30+
def tearDownClass(cls):
31+
cls.server.stop()
3332

3433
def _get_ldapobject(self, bytes_mode=None):
3534
l = LDAPObject(self.server.ldap_uri, bytes_mode=bytes_mode)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy