def setUpClass(cls): super(BaseTestCase, cls).setUpClass() cls.ldap_server = volatildap.LdapServer( initial_data=cls.directory, schemas=['core.schema', 'cosine.schema', 'inetorgperson.schema', 'nis.schema'], ) settings.DATABASES['ldap']['USER'] = cls.ldap_server.rootdn settings.DATABASES['ldap']['PASSWORD'] = cls.ldap_server.rootpw settings.DATABASES['ldap']['NAME'] = cls.ldap_server.uri
def setUpClass(cls): super(RCTestCases, cls).setUpClass() cls._slapd = volatildap.LdapServer( suffix='dc=example,dc=org', schemas=['core.schema', 'cosine.schema', 'inetorgperson.schema', 'nis.schema'], initial_data=cls.directory) settings.DATABASES['ldap']['USER'] = cls._slapd.rootdn settings.DATABASES['ldap']['PASSWORD'] = cls._slapd.rootpw settings.DATABASES['ldap']['NAME'] = cls._slapd.uri
class DiscoverLdapRunner(DiscoverRunner): """Discovers all the tests in the project This is a simple subclass of the default test runner `django.test.runner.DiscoverRunner` that creates a test LDAP right after the test databases are setup and destroys it right before the test databases are setup. It also ensure re2o's settings are using this new LDAP. """ # The `volatildap.LdapServer` instance initiated with the minimal # structure required by Re2o ldap_server = volatildap.LdapServer(suffix=suffix, rootdn=rootdn, initial_data=ldapbasic, schemas=[ 'core.schema', 'cosine.schema', 'inetorgperson.schema', 'nis.schema', radius_schema_path, samba_schema_path ]) def __init__(self, *args, **kwargs): settings.DATABASES['ldap']['USER'] = self.ldap_server.rootdn settings.DATABASES['ldap']['PASSWORD'] = self.ldap_server.rootpw settings.DATABASES['ldap']['NAME'] = self.ldap_server.uri settings.LDAP['base_user_dn'] = ldapentry_Utilisateurs[0] settings.LDAP['base_userservice_dn'] = ldapentry_service_users[0] settings.LDAP['base_usergroup_dn'] = ldapentry_posix[0] settings.LDAP['base_userservicegroup_dn'] = ldapentry_services[0] settings.LDAP['user_gid'] = ldapentry_Utilisateurs[1].get( 'gidNumber', ["500"])[0] LdapUser.base_dn = settings.LDAP['base_user_dn'] LdapUserGroup.base_dn = settings.LDAP['base_usergroup_dn'] LdapServiceUser.base_dn = settings.LDAP['base_userservice_dn'] LdapServiceUserGroup.base_dn = settings.LDAP[ 'base_userservicegroup_dn'] super(DiscoverLdapRunner, self).__init__(*args, **kwargs) def setup_databases(self, *args, **kwargs): ret = super(DiscoverLdapRunner, self).setup_databases(*args, **kwargs) print("Creating test LDAP with volatildap...") self.ldap_server.start() return ret def teardown_databases(self, *args, **kwargs): self.ldap_server.stop() print("Destroying test LDAP...") super(DiscoverLdapRunner, self).teardown_databases(*args, **kwargs)