annotate MoinMoin/_tests/ldap_testbase.py @ 3910:6fbfffffc4d1

Insert moins path more aggressively into sys.path to win the race against py.test, do insertions less often in make_test_wiki
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 31 Jul 2008 14:17:19 +0200
parents 4353a470388e
children 07862b0663fd
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
3908
4353a470388e improve Python 2.3 compatibility, add notes where 2.4 is required
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3661
diff changeset
35 Requires Python 2.4 (for subprocess module).
4353a470388e improve Python 2.3 compatibility, add notes where 2.4 is required
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3661
diff changeset
36
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 @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
38 @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
39 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40
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
41 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
42 # 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
43
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 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
45 from StringIO import StringIO
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 import signal
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47
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
48 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
49 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
50 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
51 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
52
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 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
54 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
55 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
56 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
57
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
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 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
60 """ 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
61 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
62 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
63 """
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 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 (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
79 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
80 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
81 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
82 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
83
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 class Slapd(object):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 """ 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
87 def __init__(self,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 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
89 executable=SLAPD_EXECUTABLE,
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 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
91 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
92 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
93 ):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 self.executable = executable
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 self.config = config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 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
97 self.proto = proto
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 self.ip = ip
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 self.port = port
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 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
101 if service_name == '':
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 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
103 else:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 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
105
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 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
107 """ 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
108 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
109 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
110 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
111 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
112 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
113 if self.service_name:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 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
115 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
116 started = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 if timeout:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 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
119 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
120 started = False
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 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
122 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
123 try:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 lo.simple_bind_s('', '')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 started = True
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 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
127 time.sleep(0.1)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 else:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 break
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 return started
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 def stop(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 """ 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
134 pid = self.process.pid
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 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
136 os.waitpid(pid, 0)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 class LdapEnvironment(object):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 """ 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
141
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 # 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
143 DB_CONFIG = """\
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 # 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
145 # 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
146 #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
147
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 # Set log values.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 #set_lg_regionmax 262144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 #set_lg_bsize 262144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 #set_lg_max 10485760
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 #set_tas_spins 0
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 def __init__(self,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 basedn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 rootdn, rootpw,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 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
160 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
161 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
162 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
163 ):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 self.basedn = basedn
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 self.rootdn = rootdn
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 self.rootpw = rootpw
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 self.instance = instance
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 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
169 self.coding = coding
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 self.ldap_dir = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 self.slapd_conf = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 self.timeout = timeout
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 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
175 """ 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
176 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
177 DB_CONFIG there.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 # create directories
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 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
181 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
182 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
183
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 # 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
185 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
186 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
187 f.write(db_config)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 f.close()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 # 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
191 slapd_config = slapd_config % {
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 '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
193 '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
194 '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
195 'basedn': self.basedn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 'rootdn': self.rootdn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 'rootpw': self.rootpw,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 }
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199 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
200 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
201 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
202 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
203 f.write(slapd_config)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
204 f.close()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 def start_slapd(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 """ 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
208 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
209 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
210 return started
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 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
213 """ 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
214 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
215 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
216 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
217
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 class LDIFLoader(ldif.LDIFParser):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 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
220 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
221
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 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
223 loader.parse()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 def stop_slapd(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226 """ stop a slapd """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 self.slapd.stop()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 def destroy_env(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230 """ 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
231 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
232
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
233 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
234 import py.test
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235
3661
2d5a325ae247 ldap tests: rename base class so py.test doesn't find it, skip tests if slapd is not started
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3651
diff changeset
236 class LDAPTstBase:
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 """ 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
238
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
239 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
240 """
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241
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
242 # 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
243 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
244 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
245 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
246 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
247 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
248
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
249 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
250 """ 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
251 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
252 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
253 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
254 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
255 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
256 " (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
257 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
258
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
259 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
260 """ 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
261 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
262 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
263
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 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
265 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
266