X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fdjango-ldapdb.git;a=blobdiff_plain;f=examples%2Ftests.py;h=f99ea2e39ad4c2c508b7d192eaf049932f3c7c38;hp=533df5c04dbbda6bdec0b44de51f96085107d230;hb=86f79b1135e0983d0a48e211685c57ce76ea09e0;hpb=8ce4d769e2f75d829afbcc761b01c06a6219e3e0 diff --git a/examples/tests.py b/examples/tests.py index 533df5c..f99ea2e 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -62,12 +62,18 @@ class GroupTestCase(BaseTestCase): g.usernames = ['zoouser', 'baruser'] g.save() + g = LdapGroup() + g.name = "wizgroup" + g.gid = 1002 + g.usernames = ['wizuser', 'baruser'] + g.save() + def test_filter(self): qs = LdapGroup.objects.none() self.assertEquals(len(qs), 0) qs = LdapGroup.objects.all() - self.assertEquals(len(qs), 2) + self.assertEquals(len(qs), 3) qs = LdapGroup.objects.filter(name='foogroup') self.assertEquals(len(qs), 1) @@ -78,7 +84,7 @@ class GroupTestCase(BaseTestCase): self.assertEquals(g.gid, 1000) self.assertEquals(g.usernames, ['foouser', 'baruser']) - # try to get non-existent entry + # try to filter non-existent entries qs = LdapGroup.objects.filter(name='does_not_exist') self.assertEquals(len(qs), 0) @@ -89,32 +95,67 @@ class GroupTestCase(BaseTestCase): self.assertEquals(g.gid, 1000) self.assertEquals(g.usernames, ['foouser', 'baruser']) + # try to get a non-existent entry self.assertRaises(LdapGroup.DoesNotExist, LdapGroup.objects.get, name='does_not_exist') def test_order_by(self): # ascending name qs = LdapGroup.objects.order_by('name') - self.assertEquals(len(qs), 2) + self.assertEquals(len(qs), 3) self.assertEquals(qs[0].name, 'bargroup') self.assertEquals(qs[1].name, 'foogroup') + self.assertEquals(qs[2].name, 'wizgroup') # descending name qs = LdapGroup.objects.order_by('-name') - self.assertEquals(len(qs), 2) - self.assertEquals(qs[0].name, 'foogroup') - self.assertEquals(qs[1].name, 'bargroup') + self.assertEquals(len(qs), 3) + self.assertEquals(qs[0].name, 'wizgroup') + self.assertEquals(qs[1].name, 'foogroup') + self.assertEquals(qs[2].name, 'bargroup') # ascending gid qs = LdapGroup.objects.order_by('gid') - self.assertEquals(len(qs), 2) + self.assertEquals(len(qs), 3) self.assertEquals(qs[0].gid, 1000) self.assertEquals(qs[1].gid, 1001) + self.assertEquals(qs[2].gid, 1002) # descending gid qs = LdapGroup.objects.order_by('-gid') - self.assertEquals(len(qs), 2) - self.assertEquals(qs[0].gid, 1001) - self.assertEquals(qs[1].gid, 1000) + self.assertEquals(len(qs), 3) + self.assertEquals(qs[0].gid, 1002) + self.assertEquals(qs[1].gid, 1001) + self.assertEquals(qs[2].gid, 1000) + + def test_bulk_delete(self): + LdapGroup.objects.all().delete() + + qs = LdapGroup.objects.all() + self.assertEquals(len(qs), 0) + + def test_slice(self): + qs = LdapGroup.objects.all() + objs = list(qs) + self.assertEquals(len(objs), 3) + self.assertEquals(objs[0].gid, 1000) + self.assertEquals(objs[1].gid, 1001) + self.assertEquals(objs[2].gid, 1002) + + qs = LdapGroup.objects.all() + objs = qs[:2] + for o in objs: + return + print objs + self.assertEquals(len(objs), 2) + self.assertEquals(objs[0].gid, 1000) + self.assertEquals(objs[1].gid, 1001) + return + + qs = LdapGroup.objects.all() + objs = qs[1:] + self.assertEquals(len(objs), 2) + self.assertEquals(objs[0].gid, 1001) + self.assertEquals(objs[1].gid, 1002) def test_update(self): g = LdapGroup.objects.get(name='foogroup') @@ -133,7 +174,7 @@ class GroupTestCase(BaseTestCase): g.delete() qs = LdapGroup.objects.all() - self.assertEquals(len(qs), 1) + self.assertEquals(len(qs), 2) class UserTestCase(BaseTestCase): def setUp(self): @@ -243,6 +284,10 @@ class AdminTestCase(BaseTestCase): self.assertContains(response, "foogroup") self.assertContains(response, "1000") + def test_group_delete(self): + response = self.client.post('/admin/examples/ldapgroup/foogroup/delete/', {'yes': 'post'}) + self.assertRedirects(response, '/admin/examples/ldapgroup/') + def test_group_search(self): response = self.client.get('/admin/examples/ldapgroup/?q=foo') self.assertContains(response, "Ldap groups") @@ -271,3 +316,8 @@ class AdminTestCase(BaseTestCase): response = self.client.get('/admin/examples/ldapuser/foouser/') self.assertContains(response, "foouser") self.assertContains(response, "2000") + + def test_user_delete(self): + response = self.client.post('/admin/examples/ldapuser/foouser/delete/', {'yes': 'post'}) + self.assertRedirects(response, '/admin/examples/ldapuser/') +