summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJosh Smeaton <josh.smeaton@gmail.com>2014-12-01 17:11:23 +1100
committerTim Graham <timograham@gmail.com>2014-12-12 10:17:48 -0500
commit267a1dcd9b7877d97917ba6222fd247da060f9b0 (patch)
tree70399202a3ad907f0be364a7c2be865b6923fc01 /tests
parente2868308bfa4ec165fb54b6128ee18a7b4d50643 (diff)
Fixed #23941 -- Removed implicit decimal formatting from expressions.
Diffstat (limited to 'tests')
-rw-r--r--tests/aggregation/tests.py19
-rw-r--r--tests/backends/tests.py18
2 files changed, 33 insertions, 4 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index e4b821b43d..88a5f11053 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -17,7 +17,7 @@ with warnings.catch_warnings(record=True) as w:
from django.test import TestCase
from django.test.utils import Approximate
from django.test.utils import CaptureQueriesContext
-from django.utils import six
+from django.utils import six, timezone
from django.utils.deprecation import RemovedInDjango20Warning
from .models import Author, Publisher, Book, Store
@@ -689,6 +689,19 @@ class BaseAggregateTestCase(TestCase):
self.assertNotIn('order by', qstr)
self.assertEqual(qstr.count(' join '), 0)
+ def test_decimal_max_digits_has_no_effect(self):
+ Book.objects.all().delete()
+ a1 = Author.objects.first()
+ p1 = Publisher.objects.first()
+ thedate = timezone.now()
+ for i in range(10):
+ Book.objects.create(
+ isbn="abcde{}".format(i), name="none", pages=10, rating=4.0,
+ price=9999.98, contact=a1, publisher=p1, pubdate=thedate)
+
+ book = Book.objects.aggregate(price_sum=Sum('price'))
+ self.assertEqual(book['price_sum'], Decimal("99999.80"))
+
class ComplexAggregateTestCase(TestCase):
fixtures = ["aggregation.json"]
@@ -755,8 +768,8 @@ class ComplexAggregateTestCase(TestCase):
self.assertEqual(b2.sums, 383.69)
b3 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'),
- output_field=DecimalField(max_digits=6, decimal_places=2))).get(pk=4)
- self.assertEqual(b3.sums, Decimal("383.69"))
+ output_field=DecimalField())).get(pk=4)
+ self.assertEqual(b3.sums, Approximate(Decimal("383.69"), places=2))
def test_complex_aggregations_require_kwarg(self):
with six.assertRaisesRegex(self, TypeError, 'Complex expressions require an alias'):
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index db79cd0325..1c01b4a1eb 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
import copy
import datetime
-from decimal import Decimal
+from decimal import Decimal, Rounded
import re
import threading
import unittest
@@ -1059,6 +1059,22 @@ class BackendUtilTests(TestCase):
'0.1')
equal('0.1234567890', 12, 0,
'0')
+ equal('0.1234567890', None, 0,
+ '0')
+ equal('1234567890.1234567890', None, 0,
+ '1234567890')
+ equal('1234567890.1234567890', None, 2,
+ '1234567890.12')
+ equal('0.1234', 5, None,
+ '0.1234')
+ equal('123.12', 5, None,
+ '123.12')
+ with self.assertRaises(Rounded):
+ equal('0.1234567890', 5, None,
+ '0.12346')
+ with self.assertRaises(Rounded):
+ equal('1234567890.1234', 5, None,
+ '1234600000')
class DBTestSettingsRenamedTests(IgnoreAllDeprecationWarningsMixin, TestCase):