diff options
| author | Josh Smeaton <josh.smeaton@gmail.com> | 2015-10-14 10:07:42 +1100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-10-17 15:51:04 -0400 |
| commit | 6c95b134e9b2d5641c123551c080305e90e6a89d (patch) | |
| tree | 10846791986188d080f477fd676a6741ee5b9274 /tests | |
| parent | 0922bbf18d3ae8f37e1823df2dbc270d33334548 (diff) | |
Fixed #25517 -- Made Concat function idempotent on SQLite.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/db_functions/tests.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/db_functions/tests.py b/tests/db_functions/tests.py index 00aac82a7b..c18a4b25af 100644 --- a/tests/db_functions/tests.py +++ b/tests/db_functions/tests.py @@ -7,7 +7,8 @@ from django.db import connection from django.db.models import CharField, TextField, Value as V from django.db.models.expressions import RawSQL from django.db.models.functions import ( - Coalesce, Concat, Greatest, Least, Length, Lower, Now, Substr, Upper, + Coalesce, Concat, ConcatPair, Greatest, Least, Length, Lower, Now, Substr, + Upper, ) from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.utils import six, timezone @@ -353,6 +354,19 @@ class FunctionTests(TestCase): expected = article.title + ' - ' + article.text self.assertEqual(expected.upper(), article.title_text) + @skipUnless(connection.vendor == 'sqlite', "sqlite specific implementation detail.") + def test_concat_coalesce_idempotent(self): + pair = ConcatPair(V('a'), V('b')) + # Check nodes counts + self.assertEqual(len(list(pair.flatten())), 3) + self.assertEqual(len(list(pair.coalesce().flatten())), 7) # + 2 Coalesce + 2 Value() + self.assertEqual(len(list(pair.flatten())), 3) + + def test_concat_sql_generation_idempotency(self): + qs = Article.objects.annotate(description=Concat('title', V(': '), 'summary')) + # Multiple compilations should not alter the generated query. + self.assertEqual(str(qs.query), str(qs.all().query)) + def test_lower(self): Author.objects.create(name='John Smith', alias='smithj') Author.objects.create(name='Rhonda') |
