Skip to content

Commit

Permalink
[1.2.X] Fixed #14246: Modified aggregation_regress tests so that they…
Browse files Browse the repository at this point in the history
… will pass on a variety (sqlite, Postgres, MySQL/MyISAM) of DBs.

r13712 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13714 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
kmtracey committed Sep 10, 2010
1 parent 1b0084e commit 13f1192
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tests/regressiontests/aggregation_regress/tests.py
Expand Up @@ -135,7 +135,6 @@ def test_annotation(self):
contact_id=3,
id=2,
isbn=u'067232959',
manufacture_cost=11.545,
mean_auth_age=45.0,
name='Sams Teach Yourself Django in 24 Hours',
pages=528,
Expand All @@ -144,14 +143,15 @@ def test_annotation(self):
publisher_id=2,
rating=3.0
)
# Different DB backends return different types for the extra select computation
self.assertTrue(obj.manufacture_cost == 11.545 or obj.manufacture_cost == Decimal('11.545'))

# Order of the annotate/extra in the query doesn't matter
obj = Book.objects.extra(select={'manufacture_cost' : 'price * .5'}).annotate(mean_auth_age=Avg('authors__age')).get(pk=2)
self.assertObjectAttrs(obj,
contact_id=3,
id=2,
isbn=u'067232959',
manufacture_cost=11.545,
mean_auth_age=45.0,
name=u'Sams Teach Yourself Django in 24 Hours',
pages=528,
Expand All @@ -160,14 +160,18 @@ def test_annotation(self):
publisher_id=2,
rating=3.0
)
# Different DB backends return different types for the extra select computation
self.assertTrue(obj.manufacture_cost == 11.545 or obj.manufacture_cost == Decimal('11.545'))

# Values queries can be combined with annotate and extra
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost' : 'price * .5'}).values().get(pk=2)
manufacture_cost = obj['manufacture_cost']
self.assertTrue(manufacture_cost == 11.545 or manufacture_cost == Decimal('11.545'))
del obj['manufacture_cost']
self.assertEqual(obj, {
"contact_id": 3,
"id": 2,
"isbn": u"067232959",
"manufacture_cost": 11.545,
"mean_auth_age": 45.0,
"name": u"Sams Teach Yourself Django in 24 Hours",
"pages": 528,
Expand All @@ -180,11 +184,13 @@ def test_annotation(self):
# The order of the (empty) values, annotate and extra clauses doesn't
# matter
obj = Book.objects.values().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost' : 'price * .5'}).get(pk=2)
manufacture_cost = obj['manufacture_cost']
self.assertTrue(manufacture_cost == 11.545 or manufacture_cost == Decimal('11.545'))
del obj['manufacture_cost']
self.assertEqual(obj, {
'contact_id': 3,
'id': 2,
'isbn': u'067232959',
'manufacture_cost': 11.545,
'mean_auth_age': 45.0,
'name': u'Sams Teach Yourself Django in 24 Hours',
'pages': 528,
Expand Down

0 comments on commit 13f1192

Please sign in to comment.