projects
/
matthijs
/
upstream
/
django-ldapdb.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add tests for qs.count()
[matthijs/upstream/django-ldapdb.git]
/
examples
/
tests.py
diff --git
a/examples/tests.py
b/examples/tests.py
index af8867c19fb2f0df15d1c0a4319cca0674bc5b46..abdc64809c19d592aed3575c5b34964ab74c4b44 100644
(file)
--- a/
examples/tests.py
+++ b/
examples/tests.py
@@
-68,13
+68,25
@@
class GroupTestCase(BaseTestCase):
g.usernames = ['wizuser', 'baruser']
g.save()
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)
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)
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)
qs = LdapGroup.objects.filter(name='foogroup')
self.assertEquals(len(qs), 1)
@@
-85,6
+97,9
@@
class GroupTestCase(BaseTestCase):
self.assertEquals(g.usernames, ['foouser', 'baruser'])
# try to filter non-existent entries
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)
qs = LdapGroup.objects.filter(name='does_not_exist')
self.assertEquals(len(qs), 0)
@@
-141,18
+156,35
@@
class GroupTestCase(BaseTestCase):
self.assertEquals(objs[1].gid, 1001)
self.assertEquals(objs[2].gid, 1002)
self.assertEquals(objs[1].gid, 1001)
self.assertEquals(objs[2].gid, 1002)
+ # limit only
qs = LdapGroup.objects.all()
qs = LdapGroup.objects.all()
+ objs = qs[:2]
+ 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)
objs = qs[:2]
self.assertEquals(len(objs), 2)
self.assertEquals(objs[0].gid, 1000)
self.assertEquals(objs[1].gid, 1001)
+ # offset only
qs = LdapGroup.objects.all()
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)
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')
def test_update(self):
g = LdapGroup.objects.get(name='foogroup')