Skip to content

Commit 547c98b

Browse files
committed
Skip integration tests when slapd is missing
Integration tests depend on openldap client and server binaries. Skip tests when the tools are missing. Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 4c9c526 commit 547c98b

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

Lib/slapdtest.py

Lines changed: 17 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,21 @@ 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 unittest.SkipTest(
149+
'Binary {} is missing.'.format(binary)
150+
)
151+
if self.SCHEMADIR is None:
152+
raise unittest.SkipTest(
153+
'SCHEMADIR is None, no ldap schemas were found.'
154+
)
155+
141156
def setup_rundir(self):
142157
"""
143158
creates rundir structure
@@ -283,6 +298,7 @@ def start(self):
283298
"""
284299

285300
if self._proc is None:
301+
self._check_requirements()
286302
# prepare directory structure
287303
atexit.register(self.stop)
288304
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