From: jlaine Date: Mon, 31 May 2010 11:52:10 +0000 (+0000) Subject: create / drop LDAP in tests X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=98ee4e6a25bf82ac32c2f89f17278993a14bcfba;p=matthijs%2Fupstream%2Fdjango-ldapdb.git create / drop LDAP in tests git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@880 e071eeec-0327-468d-9b6a-08194a12b294 --- diff --git a/examples/tests.py b/examples/tests.py index a8e3a3e..38a122a 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -18,11 +18,32 @@ # along with this program. If not, see . # +import ldap + from django.test import TestCase +from ldapdb import connection from examples.models import LdapUser, LdapGroup -class GroupTestCase(TestCase): +class BaseTestCase(TestCase): + def setUp(self): + cursor = connection._cursor() + for base in [LdapGroup.base_dn, LdapUser.base_dn]: + ou = base.split(',')[0].split('=')[1] + attrs = [('objectClass', ['top', 'organizationalUnit']), ('ou', [ou])] + try: + cursor.connection.add_s(base, attrs) + except ldap.ALREADY_EXISTS: + pass + + def tearDown(self): + cursor = connection._cursor() + for base in [LdapGroup.base_dn, LdapUser.base_dn]: + results = cursor.connection.search_s(base, ldap.SCOPE_SUBTREE) + for dn, attrs in reversed(results): + cursor.connection.delete_s(dn) + +class GroupTestCase(BaseTestCase): def test_create(self): g = LdapGroup() g.name = "foogroup" @@ -30,7 +51,7 @@ class GroupTestCase(TestCase): g.usernames = ['foouser'] g.save() -class UserTestCase(TestCase): +class UserTestCase(BaseTestCase): def test_create(self): u = LdapUser() u.first_name = "Foo"