mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -10,26 +10,35 @@ from . import PostgreSQLTestCase
|
|||
from .models import CITestModel
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
|
||||
@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
|
||||
class CITextTestCase(PostgreSQLTestCase):
|
||||
case_sensitive_lookups = ('contains', 'startswith', 'endswith', 'regex')
|
||||
case_sensitive_lookups = ("contains", "startswith", "endswith", "regex")
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.john = CITestModel.objects.create(
|
||||
name='JoHn',
|
||||
email='joHn@johN.com',
|
||||
description='Average Joe named JoHn',
|
||||
array_field=['JoE', 'jOhn'],
|
||||
name="JoHn",
|
||||
email="joHn@johN.com",
|
||||
description="Average Joe named JoHn",
|
||||
array_field=["JoE", "jOhn"],
|
||||
)
|
||||
|
||||
def test_equal_lowercase(self):
|
||||
"""
|
||||
citext removes the need for iexact as the index is case-insensitive.
|
||||
"""
|
||||
self.assertEqual(CITestModel.objects.filter(name=self.john.name.lower()).count(), 1)
|
||||
self.assertEqual(CITestModel.objects.filter(email=self.john.email.lower()).count(), 1)
|
||||
self.assertEqual(CITestModel.objects.filter(description=self.john.description.lower()).count(), 1)
|
||||
self.assertEqual(
|
||||
CITestModel.objects.filter(name=self.john.name.lower()).count(), 1
|
||||
)
|
||||
self.assertEqual(
|
||||
CITestModel.objects.filter(email=self.john.email.lower()).count(), 1
|
||||
)
|
||||
self.assertEqual(
|
||||
CITestModel.objects.filter(
|
||||
description=self.john.description.lower()
|
||||
).count(),
|
||||
1,
|
||||
)
|
||||
|
||||
def test_fail_citext_primary_key(self):
|
||||
"""
|
||||
|
@ -37,27 +46,39 @@ class CITextTestCase(PostgreSQLTestCase):
|
|||
clashes with an existing value isn't allowed.
|
||||
"""
|
||||
with self.assertRaises(IntegrityError):
|
||||
CITestModel.objects.create(name='John')
|
||||
CITestModel.objects.create(name="John")
|
||||
|
||||
def test_array_field(self):
|
||||
instance = CITestModel.objects.get()
|
||||
self.assertEqual(instance.array_field, self.john.array_field)
|
||||
self.assertTrue(CITestModel.objects.filter(array_field__contains=['joe']).exists())
|
||||
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])
|
||||
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')):
|
||||
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])
|
||||
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')):
|
||||
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])
|
||||
query = {"email__{}".format(lookup): string}
|
||||
self.assertSequenceEqual(
|
||||
CITestModel.objects.filter(**query), [self.john]
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue