diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/postgresql/tests.py | 4 | ||||
| -rw-r--r-- | tests/postgres_tests/test_citext.py | 19 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index 140fbbc444..db3be9bde7 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -138,6 +138,10 @@ class Tests(TestCase): for lookup in lookups: with self.subTest(lookup=lookup): self.assertIn('::text', do.lookup_cast(lookup)) + for lookup in lookups: + for field_type in ('CICharField', 'CIEmailField', 'CITextField'): + with self.subTest(lookup=lookup, field_type=field_type): + self.assertIn('::citext', do.lookup_cast(lookup, internal_type=field_type)) def test_correct_extraction_psycopg2_version(self): from django.db.backends.postgresql.base import psycopg2_version diff --git a/tests/postgres_tests/test_citext.py b/tests/postgres_tests/test_citext.py index 0a7012b072..350f34ba33 100644 --- a/tests/postgres_tests/test_citext.py +++ b/tests/postgres_tests/test_citext.py @@ -12,6 +12,7 @@ from .models import CITestModel @modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}) class CITextTestCase(PostgreSQLTestCase): + case_sensitive_lookups = ('contains', 'startswith', 'endswith', 'regex') @classmethod def setUpTestData(cls): @@ -42,3 +43,21 @@ class CITextTestCase(PostgreSQLTestCase): instance = CITestModel.objects.get() self.assertEqual(instance.array_field, self.john.array_field) self.assertTrue(CITestModel.objects.filter(array_field__contains=['joe']).exists()) + + def test_lookups_name_char(self): + for lookup in self.case_sensitive_lookups: + with self.subTest(lookup=lookup): + query = {'name__{}'.format(lookup): 'john'} + self.assertSequenceEqual(CITestModel.objects.filter(**query), [self.john]) + + def test_lookups_description_text(self): + for lookup, string in zip(self.case_sensitive_lookups, ('average', 'average joe', 'john', 'Joe.named')): + with self.subTest(lookup=lookup, string=string): + query = {'description__{}'.format(lookup): string} + self.assertSequenceEqual(CITestModel.objects.filter(**query), [self.john]) + + def test_lookups_email(self): + for lookup, string in zip(self.case_sensitive_lookups, ('john', 'john', 'john.com', 'john.com')): + with self.subTest(lookup=lookup, string=string): + query = {'email__{}'.format(lookup): string} + self.assertSequenceEqual(CITestModel.objects.filter(**query), [self.john]) |
