diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2018-12-01 23:46:28 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-01-14 14:35:41 -0500 |
| commit | c690afb873cac8035a3cb3be7c597a5ff0e4b261 (patch) | |
| tree | 19d60b4ceaf53f86a9c1ba37b7e27ac080256f13 /tests | |
| parent | 3d5e0f8394688d40036e27cfcfac295e6fe62269 (diff) | |
Refs #28643 -- Changed Avg() to use NumericOutputFieldMixin.
Keeps precision instead of forcing DecimalField to FloatField.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 10 | ||||
| -rw-r--r-- | tests/aggregation_regress/tests.py | 4 |
2 files changed, 7 insertions, 7 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 75d2ecb1c5..8cac90f020 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -865,15 +865,15 @@ class AggregateTestCase(TestCase): def test_avg_decimal_field(self): v = Book.objects.filter(rating=4).aggregate(avg_price=(Avg('price')))['avg_price'] - self.assertIsInstance(v, float) - self.assertEqual(v, Approximate(47.39, places=2)) + self.assertIsInstance(v, Decimal) + self.assertEqual(v, Approximate(Decimal('47.39'), places=2)) def test_order_of_precedence(self): p1 = Book.objects.filter(rating=4).aggregate(avg_price=(Avg('price') + 2) * 3) - self.assertEqual(p1, {'avg_price': Approximate(148.18, places=2)}) + self.assertEqual(p1, {'avg_price': Approximate(Decimal('148.18'), places=2)}) p2 = Book.objects.filter(rating=4).aggregate(avg_price=Avg('price') + 2 * 3) - self.assertEqual(p2, {'avg_price': Approximate(53.39, places=2)}) + self.assertEqual(p2, {'avg_price': Approximate(Decimal('53.39'), places=2)}) def test_combine_different_types(self): msg = 'Expression contains mixed types. You must set output_field.' @@ -1087,7 +1087,7 @@ class AggregateTestCase(TestCase): return super().as_sql(compiler, connection, function='MAX', **extra_context) qs = Publisher.objects.annotate( - price_or_median=Greatest(Avg('book__rating'), Avg('book__price')) + price_or_median=Greatest(Avg('book__rating', output_field=DecimalField()), Avg('book__price')) ).filter(price_or_median__gte=F('num_awards')).order_by('num_awards') self.assertQuerysetEqual( qs, [1, 3, 7, 9], lambda v: v.num_awards) diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py index 2b3948a0b4..64bbc13f80 100644 --- a/tests/aggregation_regress/tests.py +++ b/tests/aggregation_regress/tests.py @@ -401,7 +401,7 @@ class AggregationTests(TestCase): When(pages__lt=400, then='discount_price'), output_field=DecimalField() )))['test'], - 22.27, places=2 + Decimal('22.27'), places=2 ) def test_distinct_conditional_aggregate(self): @@ -1041,7 +1041,7 @@ class AggregationTests(TestCase): books = Book.objects.values_list("publisher__name").annotate( Count("id"), Avg("price"), Avg("authors__age"), avg_pgs=Avg("pages") ).order_by("-publisher__name") - self.assertEqual(books[0], ('Sams', 1, 23.09, 45.0, 528.0)) + self.assertEqual(books[0], ('Sams', 1, Decimal('23.09'), 45.0, 528.0)) def test_annotation_disjunction(self): qs = Book.objects.annotate(n_authors=Count("authors")).filter( |
