summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-06-14 20:09:24 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-06-14 20:09:24 +0000
commitf522555392ed9e133431437dd815ba0e84bc2394 (patch)
treec9c7be2353a4501d3b039e770bb77e74667ef467 /tests/regressiontests
parent8f441f09628d3c3c8e5abe2132ad27e007fb550c (diff)
[soc2010/query-refactor] Implemented count() (and by extension the Count() aggregate on the primary key).
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13353 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/mongodb/tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/regressiontests/mongodb/tests.py b/tests/regressiontests/mongodb/tests.py
index 3fd0ddde5c..bdc5a10727 100644
--- a/tests/regressiontests/mongodb/tests.py
+++ b/tests/regressiontests/mongodb/tests.py
@@ -1,3 +1,4 @@
+from django.db.models import Count
from django.test import TestCase
from models import Artist
@@ -25,3 +26,21 @@ class MongoTestCase(TestCase):
l = Artist.objects.get(pk=pk)
self.assertTrue(not l.good)
+
+ def test_count(self):
+ Artist.objects.create(name="Billy Joel", good=True)
+ Artist.objects.create(name="John Mellencamp", good=True)
+ Artist.objects.create(name="Warren Zevon", good=True)
+ Artist.objects.create(name="Matisyahu", good=True)
+ Artist.objects.create(name="Gary US Bonds", good=True)
+
+ self.assertEqual(Artist.objects.count(), 5)
+ self.assertEqual(Artist.objects.filter(good=True).count(), 5)
+
+ Artist.objects.create(name="Bon Iver", good=False)
+
+ self.assertEqual(Artist.objects.count(), 6)
+ self.assertEqual(Artist.objects.filter(good=True).count(), 5)
+ self.assertEqual(Artist.objects.filter(good=False).count(), 1)
+
+ self.assertEqual(Artist.objects.aggregate(c=Count("pk")), {"c": 6})