annotate MoinMoin/_tests/ldap_testbase.py @ 3651:df024fd0a129

LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 01 Jun 2008 13:43:48 +0200
parents 23851c20e53f
children 2d5a325ae247
rev   line source
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 LDAPTestBase: LDAP testing support for py.test based unit tests
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 Features
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 --------
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 * setup_class
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 * automatic creation of a temporary LDAP server environment
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 * automatic creation of a LDAP server process (slapd)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 * teardown_class
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 * LDAP server process will be killed and termination will be waited for
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 * temporary LDAP environment will be removed
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 Usage
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 -----
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 Write your own test class and derive from LDAPTestBase:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 class TestLdap(LDAPTestBase):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 def testFunction(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 server_url = self.ldap_env.slapd.url
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 lo = ldap.initialize(server_url)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 lo.simple_bind_s('', '')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 Notes
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 -----
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 On Ubuntu 8.04 there is apparmor imposing some restrictions on /usr/sbin/slapd,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 so you need to disable apparmor by invoking this as root:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 # /etc/init.d/apparmor stop
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 @copyright: 2008 by Thomas Waldmann
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 @license: GNU GPL, see COPYING for details.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
39 SLAPD_EXECUTABLE = 'slapd' # filename of LDAP server executable - if it is not
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
40 # in your PATH, you have to give full path/filename.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
41
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 import os, shutil, tempfile, time
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 from StringIO import StringIO
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 import signal
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
46 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
47 import subprocess # needs Python 2.4
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
48 except ImportError:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
49 subprocess = None
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
50
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
51 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
52 import ldap, ldif, ldap.modlist # needs python-ldap
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
53 except ImportError:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
54 ldap = None
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
55
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
56
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
57 def check_environ():
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
58 """ Check the system environment whether we are able to run.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
59 Either return some failure reason if we can't or None if everything
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
60 looks OK.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
61 """
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
62 if subprocess is None:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
63 return "You need at least python 2.4 to use ldap_testbase."
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
64 if ldap is None:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
65 return "You need python-ldap installed to use ldap_testbase."
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
66 slapd = False
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
67 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
68 p = subprocess.Popen([SLAPD_EXECUTABLE, '-V'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
69 pid = p.pid
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
70 rc = p.wait()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
71 if pid and rc == 1:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
72 slapd = True # it works
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
73 except OSError, err:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
74 import errno
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
75 if not (err.errno == errno.ENOENT or
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
76 (err.errno == 3 and os.name == 'nt')):
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
77 raise
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
78 if not slapd:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
79 return "Can't start %s (see SLAPD_EXECUTABLE)." % SLAPD_EXECUTABLE
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
80 return None
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
81
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 class Slapd(object):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 """ Manage a slapd process for testing purposes """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 def __init__(self,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 config=None, # config filename for -f
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
87 executable=SLAPD_EXECUTABLE,
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 debug_flags='', # None, # for -d stats,acl,args,trace,sync,config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 proto='ldap', ip='127.0.0.1', port=3890, # use -h proto://ip:port
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 service_name='' # defaults to -n executable:port, use None to not use -n
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 ):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 self.executable = executable
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 self.config = config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 self.debug_flags = debug_flags
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 self.proto = proto
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 self.ip = ip
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 self.port = port
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 self.url = '%s://%s:%d' % (proto, ip, port) # can be used for ldap.initialize() call
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 if service_name == '':
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 self.service_name = '%s:%d' % (executable, port)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 else:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 self.service_name = service_name
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 def start(self, timeout=0):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 """ start a slapd process and optionally wait up to timeout seconds until it responds """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 args = [self.executable, '-h', self.url, ]
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 if self.config is not None:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 args.extend(['-f', self.config])
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 if self.debug_flags is not None:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 args.extend(['-d', self.debug_flags])
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 if self.service_name:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 args.extend(['-n', self.service_name])
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 self.process = subprocess.Popen(args)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 started = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 if timeout:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 lo = ldap.initialize(self.url)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3) # ldap v2 is outdated
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 started = False
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 wait_until = time.time() + timeout
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 while time.time() < wait_until:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 try:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 lo.simple_bind_s('', '')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 started = True
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 except ldap.SERVER_DOWN, err:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 time.sleep(0.1)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 else:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 break
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 return started
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 def stop(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 """ stop this slapd process and wait until it has terminated """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 pid = self.process.pid
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 os.kill(pid, signal.SIGTERM)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 os.waitpid(pid, 0)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 class LdapEnvironment(object):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 """ Manage a (temporary) environment for running a slapd in it """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 # default DB_CONFIG bdb configuration file contents
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 DB_CONFIG = """\
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 # STRANGE: if i use those settings, after the test slapd goes to 100% and doesn't terminate on SIGTERM
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 # Set the database in memory cache size.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 #set_cachesize 0 10000000 1
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 # Set log values.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147 #set_lg_regionmax 262144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 #set_lg_bsize 262144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 #set_lg_max 10485760
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 #set_tas_spins 0
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 def __init__(self,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 basedn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 rootdn, rootpw,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 instance=0, # use different values when running multiple LdapEnvironments
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 schema_dir='/etc/ldap/schema', # directory with schemas
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 coding='utf-8', # coding used for config files
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160 timeout=10, # how long to wait for slapd starting [s]
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 ):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 self.basedn = basedn
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 self.rootdn = rootdn
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 self.rootpw = rootpw
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 self.instance = instance
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 self.schema_dir = schema_dir
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 self.coding = coding
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 self.ldap_dir = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169 self.slapd_conf = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 self.timeout = timeout
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 def create_env(self, slapd_config, db_config=DB_CONFIG):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 """ create a temporary LDAP server environment in a temp. directory,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 including writing a slapd.conf (see configure_slapd) and a
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 DB_CONFIG there.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 # create directories
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 self.ldap_dir = tempfile.mkdtemp(prefix='LdapEnvironment-%d.' % self.instance)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 self.ldap_db_dir = os.path.join(self.ldap_dir, 'db')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 os.mkdir(self.ldap_db_dir)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 # create DB_CONFIG for bdb backend
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183 db_config_fname = os.path.join(self.ldap_db_dir, 'DB_CONFIG')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 f = open(db_config_fname, 'w')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 f.write(db_config)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186 f.close()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 # create slapd.conf from content template in slapd_config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189 slapd_config = slapd_config % {
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 'ldap_dir': self.ldap_dir,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 'ldap_db_dir': self.ldap_db_dir,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 'schema_dir': self.schema_dir,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193 'basedn': self.basedn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 'rootdn': self.rootdn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
195 'rootpw': self.rootpw,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 }
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 if isinstance(slapd_config, unicode):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 slapd_config = slapd_config.encode(self.coding)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199 self.slapd_conf = os.path.join(self.ldap_dir, "slapd.conf")
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 f = open(self.slapd_conf, 'w')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 f.write(slapd_config)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 f.close()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
203
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
204 def start_slapd(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205 """ start a slapd and optionally wait until it talks with us """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 self.slapd = Slapd(config=self.slapd_conf, port=3890+self.instance)
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
207 started = self.slapd.start(timeout=self.timeout)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
208 return started
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 def load_directory(self, ldif_content):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 """ load the directory with the ldif_content (str) """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 lo = ldap.initialize(self.slapd.url)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3) # ldap v2 is outdated
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 lo.simple_bind_s(self.rootdn, self.rootpw)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 class LDIFLoader(ldif.LDIFParser):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 def handle(self, dn, entry):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 lo.add_s(dn, ldap.modlist.addModlist(entry))
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 loader = LDIFLoader(StringIO(ldif_content))
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 loader.parse()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 def stop_slapd(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224 """ stop a slapd """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 self.slapd.stop()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 def destroy_env(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228 """ remove the temporary LDAP server environment """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 shutil.rmtree(self.ldap_dir)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
231 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
232 import py.test
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
234 class LDAPTestBase:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
235 """ Test base class for py.test based tests which need a LDAP server to talk to.
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
236
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
237 Inherit your test class from this base class to test LDAP stuff.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
238 """
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
240 # You MUST define these in your derived class:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
241 slapd_config = None # a string with your slapd.conf template
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
242 ldif_content = None # a string with your ldif contents
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
243 basedn = None # your base DN
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
244 rootdn = None # root DN
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
245 rootpw = None # root password
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
247 def setup_class(self):
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
248 """ Create LDAP server environment, start slapd """
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
249 self.ldap_env = LdapEnvironment(self.basedn, self.rootdn, self.rootpw)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
250 self.ldap_env.create_env(slapd_config=self.slapd_config)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
251 started = self.ldap_env.start_slapd()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
252 if not started:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
253 py.test.skip("Failed to start %s process, please see your syslog / log files"
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
254 " (and check if stopping apparmor helps, in case you use it)." % SLAPD_EXECUTABLE)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
255 self.ldap_env.load_directory(ldif_content=self.ldif_content)
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
257 def teardown_class(self):
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
258 """ Stop slapd, remove LDAP server environment """
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
259 self.ldap_env.stop_slapd()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
260 self.ldap_env.destroy_env()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
261
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
262 except ImportError:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
263 pass # obviously py.test not in use
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
264