X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=examples%2Ftests.py;h=f98fbdf307abf944ba018aaa329cb59977ea42f2;hb=8a9319586dc6fb44b83ba161bcc5a651da536cf1;hp=9755752da3c04cf384a812630e6ad04169266e52;hpb=adf0e789122e9362c67921492500edf844876219;p=matthijs%2Fupstream%2Fdjango-ldapdb.git diff --git a/examples/tests.py b/examples/tests.py index 9755752..f98fbdf 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -29,8 +29,9 @@ 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])] + rdn = base.split(',')[0] + key, val = rdn.split('=') + attrs = [('objectClass', ['top', 'organizationalUnit']), (key, [val])] try: cursor.connection.add_s(base, attrs) except ldap.ALREADY_EXISTS: @@ -39,9 +40,12 @@ class BaseTestCase(TestCase): 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) + try: + results = cursor.connection.search_s(base, ldap.SCOPE_SUBTREE) + for dn, attrs in reversed(results): + cursor.connection.delete_s(dn) + except ldap.NO_SUCH_OBJECT: + pass class GroupTestCase(BaseTestCase): def setUp(self): @@ -69,6 +73,12 @@ class GroupTestCase(BaseTestCase): qs = LdapGroup.objects.filter(name='foogroup') self.assertEquals(len(qs), 1) + g = qs[0] + self.assertEquals(g.dn, 'cn=foogroup,ou=groups,dc=nodomain') + self.assertEquals(g.name, 'foogroup') + self.assertEquals(g.gid, 1000) + self.assertEquals(g.usernames, ['foouser', 'baruser']) + qs = LdapGroup.objects.filter(name='does_not_exist') self.assertEquals(len(qs), 0) @@ -83,10 +93,14 @@ class GroupTestCase(BaseTestCase): def test_update(self): g = LdapGroup.objects.get(name='foogroup') + + g.gid = 1002 + g.usernames = ['foouser2', 'baruser2'] + g.save() + + # make sure DN gets updated if we change the pk g.name = 'foogroup2' g.save() - - # make sure DN gets updated self.assertEquals(g.dn, 'cn=foogroup2,ou=groups,dc=nodomain') def test_delete(self): @@ -126,6 +140,16 @@ class UserTestCase(BaseTestCase): self.assertRaises(LdapUser.DoesNotExist, LdapUser.objects.get, username='does_not_exist') + def test_update(self): + u = LdapUser.objects.get(username='foouser') + u.first_name = u'Fôo2' + u.save() + + # make sure DN gets updated if we change the pk + u.username = 'foouser2' + u.save() + self.assertEquals(u.dn, 'uid=foouser2,ou=people,dc=nodomain') + class AdminTestCase(BaseTestCase): fixtures = ['test_users.json']