X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=examples%2Ftests.py;h=38a122ab05d2c95a0b3996efb957cf76673d179d;hb=98ee4e6a25bf82ac32c2f89f17278993a14bcfba;hp=dba0f5ee086f9f704b7d140c35d3e3163bfb8787;hpb=eac1a9e03d8e7dc89abf60d1e026c67164edbcb0;p=matthijs%2Fupstream%2Fdjango-ldapdb.git diff --git a/examples/tests.py b/examples/tests.py index dba0f5e..38a122a 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -18,18 +18,40 @@ # 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" g.gid = 1000 + g.usernames = ['foouser'] g.save() -class UserTestCase(TestCase): +class UserTestCase(BaseTestCase): def test_create(self): u = LdapUser() u.first_name = "Foo"