mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -5,25 +5,27 @@ from . import PostgreSQLTestCase
|
||||
from .models import CharFieldModel, TextFieldModel
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
|
||||
@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
|
||||
class UnaccentTest(PostgreSQLTestCase):
|
||||
|
||||
Model = CharFieldModel
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.Model.objects.bulk_create([
|
||||
cls.Model(field="àéÖ"),
|
||||
cls.Model(field="aeO"),
|
||||
cls.Model(field="aeo"),
|
||||
])
|
||||
cls.Model.objects.bulk_create(
|
||||
[
|
||||
cls.Model(field="àéÖ"),
|
||||
cls.Model(field="aeO"),
|
||||
cls.Model(field="aeo"),
|
||||
]
|
||||
)
|
||||
|
||||
def test_unaccent(self):
|
||||
self.assertQuerysetEqual(
|
||||
self.Model.objects.filter(field__unaccent="aeO"),
|
||||
["àéÖ", "aeO"],
|
||||
transform=lambda instance: instance.field,
|
||||
ordered=False
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
def test_unaccent_chained(self):
|
||||
@@ -35,39 +37,39 @@ class UnaccentTest(PostgreSQLTestCase):
|
||||
self.Model.objects.filter(field__unaccent__iexact="aeO"),
|
||||
["àéÖ", "aeO", "aeo"],
|
||||
transform=lambda instance: instance.field,
|
||||
ordered=False
|
||||
ordered=False,
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.Model.objects.filter(field__unaccent__endswith="éÖ"),
|
||||
["àéÖ", "aeO"],
|
||||
transform=lambda instance: instance.field,
|
||||
ordered=False
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
def test_unaccent_with_conforming_strings_off(self):
|
||||
"""SQL is valid when standard_conforming_strings is off."""
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute('SHOW standard_conforming_strings')
|
||||
disable_conforming_strings = cursor.fetchall()[0][0] == 'on'
|
||||
cursor.execute("SHOW standard_conforming_strings")
|
||||
disable_conforming_strings = cursor.fetchall()[0][0] == "on"
|
||||
if disable_conforming_strings:
|
||||
cursor.execute('SET standard_conforming_strings TO off')
|
||||
cursor.execute("SET standard_conforming_strings TO off")
|
||||
try:
|
||||
self.assertQuerysetEqual(
|
||||
self.Model.objects.filter(field__unaccent__endswith='éÖ'),
|
||||
['àéÖ', 'aeO'],
|
||||
self.Model.objects.filter(field__unaccent__endswith="éÖ"),
|
||||
["àéÖ", "aeO"],
|
||||
transform=lambda instance: instance.field,
|
||||
ordered=False,
|
||||
)
|
||||
finally:
|
||||
if disable_conforming_strings:
|
||||
cursor.execute('SET standard_conforming_strings TO on')
|
||||
cursor.execute("SET standard_conforming_strings TO on")
|
||||
|
||||
def test_unaccent_accentuated_needle(self):
|
||||
self.assertQuerysetEqual(
|
||||
self.Model.objects.filter(field__unaccent="aéÖ"),
|
||||
["àéÖ", "aeO"],
|
||||
transform=lambda instance: instance.field,
|
||||
ordered=False
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
@@ -76,4 +78,5 @@ class UnaccentTextFieldTest(UnaccentTest):
|
||||
TextField should have the exact same behavior as CharField
|
||||
regarding unaccent lookups.
|
||||
"""
|
||||
|
||||
Model = TextFieldModel
|
||||
|
||||
Reference in New Issue
Block a user