# -*- coding: utf-8 -*- import pytest from authentic2_provisionning_ldap.ldap_utils import Slapd, has_slapd from django.contrib.auth import get_user_model from django.core.exceptions import ImproperlyConfigured from authentic2.a2_rbac.utils import get_default_ou from django_rbac.utils import get_ou_model pytestmark = pytest.mark.skipunless(has_slapd(), reason='slapd is not installed') slapd = None def setup_module(module): global slapd slapd = Slapd() slapd.add_ldif('''dn: uid=etienne.michu,o=orga objectClass: inetOrgPerson userPassword: pass uid: etienne.michu cn: Étienne Michu sn: Michu gn: Étienne mail: [email protected]''') def teardown_module(module): slapd.clean()
import ldap from django.test import TestCase from unittest import skipUnless from authentic2_provisionning_ldap.ldap_utils import Slapd, has_slapd from django.core.management import call_command from authentic2 import compat @skipUnless(has_slapd(), 'slapd is not installed') class LDAPBaseTestCase(TestCase): slapd = None def setUp(self): if self.slapd is None: self.slapd = Slapd() self.slapd.checkpoint() # fresh connection self.conn = self.slapd.get_connection() def tearDown(self): self.slapd.restore() class WhoamiTest(LDAPBaseTestCase): def test_whoami(self): self.conn.simple_bind_s('uid=admin,o=orga', 'admin') assert self.conn.whoami_s() == 'dn:uid=admin,o=orga' class ProvisionTest(LDAPBaseTestCase): def test_ldap_provisionning(self):