summaryrefslogtreecommitdiff
path: root/tests/annotations
diff options
context:
space:
mode:
authorJosh Smeaton <josh.smeaton@gmail.com>2015-03-20 15:47:43 +1100
committerJosh Smeaton <josh.smeaton@gmail.com>2015-03-22 17:28:42 +1100
commit127b3873d03704f77428b984de022664b268314e (patch)
tree8c8c8efaf8d16eb9f27872f62d6af36393a7edc9 /tests/annotations
parenta6bada1ee0c3756e4b8d6bd4b4346dd5235c78ce (diff)
Fixed #24508 -- Made annotations commutative
Diffstat (limited to 'tests/annotations')
-rw-r--r--tests/annotations/tests.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index b5159b6120..45da5e49de 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -182,6 +182,14 @@ class NonAggregateAnnotationTestCase(TestCase):
sum_rating=Sum('rating')
).filter(sum_rating=F('nope')))
+ def test_combined_annotation_commutative(self):
+ book1 = Book.objects.annotate(adjusted_rating=F('rating') + 2).get(pk=self.b1.pk)
+ book2 = Book.objects.annotate(adjusted_rating=2 + F('rating')).get(pk=self.b1.pk)
+ self.assertEqual(book1.adjusted_rating, book2.adjusted_rating)
+ book1 = Book.objects.annotate(adjusted_rating=F('rating') + None).get(pk=self.b1.pk)
+ book2 = Book.objects.annotate(adjusted_rating=None + F('rating')).get(pk=self.b1.pk)
+ self.assertEqual(book1.adjusted_rating, book2.adjusted_rating)
+
def test_update_with_annotation(self):
book_preupdate = Book.objects.get(pk=self.b2.pk)
Book.objects.annotate(other_rating=F('rating') - 1).update(rating=F('other_rating'))