Skip to content

Commit

Permalink
re-factored slapd.py, t_cext.py and t_search.py: new class SlapdTestC…
Browse files Browse the repository at this point in the history
…ase used
  • Loading branch information
stroeder committed Apr 26, 2017
1 parent 48a8cb1 commit 2ce408c
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 181 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Tests/
which requires fairly recent OpenLDAP builds
* env vars can be set for slapd.py to tweak path names
of executables, temporary and schema data to be used
* new class SlapdTestCase

----------------------------------------------------------------
Released 2.4.35 2017-04-25
Expand Down Expand Up @@ -1392,4 +1393,4 @@ Released 2.0.0pre02 2002-02-01
----------------------------------------------------------------
Released 1.10alpha3 2000-09-19

$Id: CHANGES,v 1.428 2017/04/26 13:12:52 stroeder Exp $
$Id: CHANGES,v 1.429 2017/04/26 14:54:14 stroeder Exp $
50 changes: 42 additions & 8 deletions Tests/slapd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess
import logging
import base64
import unittest

# determine log level
try:
Expand Down Expand Up @@ -106,14 +107,6 @@ def __init__(self):
self._tmpdir = os.path.join(self.TMPDIR, 'python-ldap-test')
self._slapd_conf = os.path.join(self._tmpdir, "slapd.conf")
self._db_directory = os.path.join(self._tmpdir, "openldap-data")
# init directory structure
delete_directory_content(self._tmpdir)
mkdirs(self._tmpdir)
mkdirs(self._db_directory)

def __del__(self):
self.stop()
delete_directory_content(self._tmpdir)

def _gen_config(self):
"""
Expand Down Expand Up @@ -144,6 +137,10 @@ def start(self):
if self._proc is None:
ok = False
config_path = None
# init directory structure
delete_directory_content(self._tmpdir)
mkdirs(self._tmpdir)
mkdirs(self._db_directory)
try:
self._write_config()
self._test_configuration()
Expand Down Expand Up @@ -378,3 +375,40 @@ def started(self):
''
])
)


class SlapdTestCase(unittest.TestCase):
"""
test class which also clones or initializes a running slapd
"""

server = None

def _open_ldap_conn(self, who=None, cred=None):
"""
return a LDAPObject instance after simple bind
"""
import ldap
ldap_conn = self.ldap_object_class(self.server.ldap_uri)
ldap_conn.protocol_version = 3
ldap_conn.set_option(ldap.OPT_REFERRALS,0)
ldap_conn.simple_bind_s(who or self.server.root_dn, cred or self.server.root_pw)
return ldap_conn

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

@classmethod
def tearDownClass(cls):
try:
cls.server.stop()
except Exception, err:
pass
try:
delete_directory_content(cls.server._tmpdir)
except Exception, err:
pass
Loading

0 comments on commit 2ce408c

Please sign in to comment.