diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2017-03-29 22:29:53 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-03-29 13:29:53 -0400 |
| commit | 068d75688f28f9a1530b771ae1d625f41e98cd82 (patch) | |
| tree | a1e4b40c4425de439990d8eaa38553fe8374280f /tests/db_functions | |
| parent | d5977e492e6e8eb7ba0ac81f85c27d56db85b78c (diff) | |
Refs #18247 -- Fixed SQLite QuerySet filtering on decimal result of Least and Greatest.
Diffstat (limited to 'tests/db_functions')
| -rw-r--r-- | tests/db_functions/models.py | 5 | ||||
| -rw-r--r-- | tests/db_functions/tests.py | 21 |
2 files changed, 25 insertions, 1 deletions
diff --git a/tests/db_functions/models.py b/tests/db_functions/models.py index bfcdb7759e..24ffba78fc 100644 --- a/tests/db_functions/models.py +++ b/tests/db_functions/models.py @@ -49,3 +49,8 @@ class DTModel(models.Model): def __str__(self): return 'DTModel({0})'.format(self.name) + + +class DecimalModel(models.Model): + n1 = models.DecimalField(decimal_places=2, max_digits=6) + n2 = models.DecimalField(decimal_places=2, max_digits=6) diff --git a/tests/db_functions/tests.py b/tests/db_functions/tests.py index c86e8eb43f..729de126bd 100644 --- a/tests/db_functions/tests.py +++ b/tests/db_functions/tests.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta +from decimal import Decimal from unittest import skipIf, skipUnless from django.db import connection @@ -11,7 +12,7 @@ from django.db.models.functions import ( from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.utils import timezone -from .models import Article, Author, Fan +from .models import Article, Author, DecimalModel, Fan lorem_ipsum = """ @@ -202,6 +203,15 @@ class FunctionTests(TestCase): author.refresh_from_db() self.assertEqual(author.alias, 'Jim') + def test_greatest_decimal_filter(self): + obj = DecimalModel.objects.create(n1=Decimal('1.1'), n2=Decimal('1.2')) + self.assertCountEqual( + DecimalModel.objects.annotate( + greatest=Greatest('n1', 'n2'), + ).filter(greatest=Decimal('1.2')), + [obj], + ) + def test_least(self): now = timezone.now() before = now - timedelta(hours=1) @@ -297,6 +307,15 @@ class FunctionTests(TestCase): author.refresh_from_db() self.assertEqual(author.alias, 'James Smith') + def test_least_decimal_filter(self): + obj = DecimalModel.objects.create(n1=Decimal('1.1'), n2=Decimal('1.2')) + self.assertCountEqual( + DecimalModel.objects.annotate( + least=Least('n1', 'n2'), + ).filter(least=Decimal('1.1')), + [obj], + ) + def test_concat(self): Author.objects.create(name='Jayden') Author.objects.create(name='John Smith', alias='smithj', goes_by='John') |
