X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fdjango-ldapdb.git;a=blobdiff_plain;f=examples%2Ftests.py;h=0905e1298da4de8e8d487a74b0ca8cca9e753586;hp=51c4183e9ef12b9f1771275c3121681cf38c4607;hb=59ae68e8883fcccebfda84a1f4bfba56a8b6cc2d;hpb=baba34a193fe7d304d86003b19f36ed638c7ec80 diff --git a/examples/tests.py b/examples/tests.py index 51c4183..0905e12 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -41,12 +41,12 @@ from examples.models import LdapUser, LdapGroup class BaseTestCase(TestCase): def setUp(self): cursor = ldapdb.connection._cursor() - for base in [LdapGroup.base_dn, LdapUser.base_dn]: - rdn = base.split(',')[0] + for dn in [LdapGroup.base_dn, LdapUser.base_dn]: + rdn = dn.split(',')[0] key, val = rdn.split('=') attrs = [('objectClass', ['top', 'organizationalUnit']), (key, [val])] try: - cursor.connection.add_s(base, attrs) + cursor.connection.add_s(dn, attrs) except ldap.ALREADY_EXISTS: pass @@ -272,6 +272,42 @@ class UserTestCase(BaseTestCase): u.save() self.assertEquals(u.dn, 'uid=foouser2,%s' % LdapUser.base_dn) +class ScopedTestCase(BaseTestCase): + def setUp(self): + super(ScopedTestCase, self).setUp() + + cursor = ldapdb.connection._cursor() + self.scoped_dn = "ou=contacts,%s" % LdapGroup.base_dn + attrs = [('objectClass', ['top', 'organizationalUnit']), ("ou", ["contacts"])] + cursor.connection.add_s(self.scoped_dn, attrs) + + def test_scope(self): + ScopedGroup = LdapGroup.scoped(self.scoped_dn) + + # create group + g = LdapGroup() + g.name = "foogroup" + g.gid = 1000 + g.save() + + qs = LdapGroup.objects.all() + self.assertEquals(qs.count(), 1) + + qs = ScopedGroup.objects.all() + self.assertEquals(qs.count(), 0) + + # create scoped group + g2 = ScopedGroup() + g2.name = "scopedgroup" + g2.gid = 5000 + g2.save() + + qs = LdapGroup.objects.all() + self.assertEquals(qs.count(), 2) + + qs = ScopedGroup.objects.all() + self.assertEquals(qs.count(), 1) + class AdminTestCase(BaseTestCase): fixtures = ['test_users.json'] @@ -340,9 +376,17 @@ class AdminTestCase(BaseTestCase): self.assertContains(response, "foogroup") self.assertContains(response, "1000") + def test_group_add(self): + response = self.client.post('/admin/examples/ldapgroup/add/', {'gid': '1002', 'name': 'wizgroup'}) + self.assertRedirects(response, '/admin/examples/ldapgroup/') + qs = LdapGroup.objects.all() + self.assertEquals(qs.count(), 3) + def test_group_delete(self): response = self.client.post('/admin/examples/ldapgroup/foogroup/delete/', {'yes': 'post'}) self.assertRedirects(response, '/admin/examples/ldapgroup/') + qs = LdapGroup.objects.all() + self.assertEquals(qs.count(), 1) def test_group_search(self): response = self.client.get('/admin/examples/ldapgroup/?q=foo')