slapdtest Spawning test instances of OpenLDAP’s slapd server

The module is used for testing python-ldap itself but can be used for automatically testing any OpenLDAP-based configuration setup.

This module is pure Python and does not rely on any non-standard modules. Therefore it can be used stand-alone without the rest of the python-ldap package.

Test fixtures for the popular pytest framework are developed in an external project, pytest-ldap.

Functions

Classes

class slapdtest.SlapdObject

Controller class for a slapd instance, OpenLDAP’s server.

This class creates a temporary data store for slapd, runs it listening on a private Unix domain socket and TCP port, and initializes it with a top-level entry and the root user.

When a reference to an instance of this class is lost, the slapd server is shut down.

An instance can be used as a context manager. When exiting the context manager, the slapd server is shut down and the temporary data store is removed.

Parameters:openldap_schema_files – A list of schema names or schema paths to load at startup. By default this only contains core.

Changed in version 3.1: Added context manager functionality

gen_config()

generates a slapd.conf and returns it as one string

for generating specific static configuration files you have to override this method

ldapadd(ldif, extra_args=None)

Runs ldapadd on this slapd instance, passing it the ldif content

ldapdelete(dn, recursive=False, extra_args=None)

Runs ldapdelete on this slapd instance, deleting ‘dn’

ldapmodify(ldif, extra_args=None)

Runs ldapadd on this slapd instance, passing it the ldif content

ldapwhoami(extra_args=None)

Runs ldapwhoami on this slapd instance

restart()

Restarts the slapd server with same data

setup_rundir()

creates rundir structure

for setting up a custom directory structure you have to override this method

slapadd(ldif, extra_args=None)

Runs slapadd on this slapd instance, passing it the ldif content

start()

Starts the slapd server process running, and waits for it to come up.

stop()

Stops the slapd server, and waits for it to terminate and cleans up

wait()

Waits for the slapd process to terminate by itself.

class slapdtest.SlapdTestCase(methodName='runTest')

test class which also clones or initializes a running slapd

server_class

alias of SlapdObject

classmethod setUpClass()

Hook method for setting up class fixture before running tests in the class.

classmethod tearDownClass()

Hook method for deconstructing the class fixture after running all tests in the class.