Skip to content

Commit

Permalink
Merge pull request #8 – Tests: Check for LDAP schema and slapd binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Viktorin authored and GitHub committed Nov 25, 2017
2 parents b587fd6 + c3876a0 commit 4af1d54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
14 changes: 13 additions & 1 deletion Lib/slapdtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class SlapdObject(object):
elif os.path.isdir("/etc/ldap/schema"):
SCHEMADIR = "/etc/ldap/schema"
else:
PATH_SCHEMA_CORE = None
SCHEMADIR = None
PATH_LDAPADD = os.path.join(BINDIR, 'ldapadd')
PATH_LDAPMODIFY = os.path.join(BINDIR, 'ldapmodify')
PATH_LDAPWHOAMI = os.path.join(BINDIR, 'ldapwhoami')
Expand All @@ -138,6 +138,17 @@ def __init__(self):
ldapi_path = os.path.join(self.testrundir, 'ldapi')
self.ldapi_uri = "ldapi://%s" % quote_plus(ldapi_path)

def _check_requirements(self):
binaries = [
self.PATH_LDAPADD, self.PATH_LDAPMODIFY, self.PATH_LDAPWHOAMI,
self.PATH_SLAPD, self.PATH_SLAPTEST
]
for binary in binaries:
if not os.path.isfile(binary):
raise ValueError('Binary {} is missing.'.format(binary))
if self.SCHEMADIR is None:
raise ValueError('SCHEMADIR is None, ldap schemas are missing.')

def setup_rundir(self):
"""
creates rundir structure
Expand Down Expand Up @@ -283,6 +294,7 @@ def start(self):
"""

if self._proc is None:
self._check_requirements()
# prepare directory structure
atexit.register(self.stop)
self._cleanup_rundir()
Expand Down
25 changes: 12 additions & 13 deletions Tests/t_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@
from slapdtest import SlapdObject
from ldap.ldapobject import LDAPObject

server = None


class TestBinds(unittest.TestCase):

def setUp(self):
global server
if server is None:
server = SlapdObject()
server.start()
@classmethod
def setUpClass(cls):
cls.server = SlapdObject()
cls.server.start()

cls.unicode_val = "abc\U0001f498def"
cls.unicode_val_bytes = cls.unicode_val.encode('utf-8')

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

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

def _get_ldapobject(self, bytes_mode=None):
l = LDAPObject(self.server.ldap_uri, bytes_mode=bytes_mode)
Expand Down

0 comments on commit 4af1d54

Please sign in to comment.