X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=examples%2Ftests.py;h=abdc64809c19d592aed3575c5b34964ab74c4b44;hb=ddbd5c9e9d0d3343f38906906793bb84a672ad5b;hp=d41d576b81b5c9a72af82ccfe3cdb3d33372dbd4;hpb=607a29c44721a799b562de30c50846d633a32933;p=matthijs%2Fupstream%2Fdjango-ldapdb.git diff --git a/examples/tests.py b/examples/tests.py index d41d576..abdc648 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -68,29 +68,44 @@ class GroupTestCase(BaseTestCase): g.usernames = ['wizuser', 'baruser'] g.save() - def test_filter(self): + def test_count(self): + # empty query + qs = LdapGroup.objects.none() + self.assertEquals(qs.count(), 0) + qs = LdapGroup.objects.none() self.assertEquals(len(qs), 0) + # all query + qs = LdapGroup.objects.all() + self.assertEquals(qs.count(), 3) + qs = LdapGroup.objects.all() self.assertEquals(len(qs), 3) + def test_filter(self): + qs = LdapGroup.objects.filter(name='foogroup') + self.assertEquals(qs.count(), 1) + 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.dn, 'cn=foogroup,%s' % LdapGroup.base_dn) self.assertEquals(g.name, 'foogroup') self.assertEquals(g.gid, 1000) self.assertEquals(g.usernames, ['foouser', 'baruser']) # try to filter non-existent entries + qs = LdapGroup.objects.filter(name='does_not_exist') + self.assertEquals(qs.count(), 0) + qs = LdapGroup.objects.filter(name='does_not_exist') self.assertEquals(len(qs), 0) def test_get(self): g = LdapGroup.objects.get(name='foogroup') - self.assertEquals(g.dn, 'cn=foogroup,ou=groups,dc=nodomain') + self.assertEquals(g.dn, 'cn=foogroup,%s' % LdapGroup.base_dn) self.assertEquals(g.name, 'foogroup') self.assertEquals(g.gid, 1000) self.assertEquals(g.usernames, ['foouser', 'baruser']) @@ -141,22 +156,35 @@ class GroupTestCase(BaseTestCase): self.assertEquals(objs[1].gid, 1001) self.assertEquals(objs[2].gid, 1002) + # limit only qs = LdapGroup.objects.all() objs = qs[:2] - for o in objs: - return - print objs + self.assertEquals(objs.count(), 2) + + objs = qs[:2] self.assertEquals(len(objs), 2) self.assertEquals(objs[0].gid, 1000) self.assertEquals(objs[1].gid, 1001) - return + # offset only qs = LdapGroup.objects.all() + objs = qs[1:] + self.assertEquals(objs.count(), 2) + objs = qs[1:] self.assertEquals(len(objs), 2) self.assertEquals(objs[0].gid, 1001) self.assertEquals(objs[1].gid, 1002) + # offset and limit + qs = LdapGroup.objects.all() + objs = qs[1:2] + self.assertEquals(objs.count(), 1) + + objs = qs[1:2] + self.assertEquals(len(objs), 1) + self.assertEquals(objs[0].gid, 1001) + def test_update(self): g = LdapGroup.objects.get(name='foogroup') @@ -167,7 +195,7 @@ class GroupTestCase(BaseTestCase): # make sure DN gets updated if we change the pk g.name = 'foogroup2' g.save() - self.assertEquals(g.dn, 'cn=foogroup2,ou=groups,dc=nodomain') + self.assertEquals(g.dn, 'cn=foogroup2,%s' % LdapGroup.base_dn) def test_values(self): qs = LdapGroup.objects.values('name') @@ -228,7 +256,7 @@ class UserTestCase(BaseTestCase): # 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') + self.assertEquals(u.dn, 'uid=foouser2,%s' % LdapUser.base_dn) class AdminTestCase(BaseTestCase): fixtures = ['test_users.json']