Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions tests/db_functions/comparison/test_collate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import connection
from django.db.models import F, Value
from django.db.models.functions import Collate
from django.db.models import F, Value, TextField
from django.db.models.functions import Collate, Cast
from django.test import TestCase

from ..models import Author
Expand All @@ -13,10 +13,12 @@ def setUpTestData(cls):
cls.author2 = Author.objects.create(alias="A", name="Jones 2")

def test_collate_filter_ci(self):
collation = connection.features.test_collations.get("ci")
if not collation:
collation_ci = connection.features.test_collations.get("ci")
if not collation_ci:
self.skipTest("This backend does not support case-insensitive collations.")
qs = Author.objects.filter(alias=Collate(Value("a"), collation))
qs = Author.objects.annotate(
alias_ci=Cast("alias", TextField(db_collation=collation_ci))
).filter(alias_ci=Collate(Value("a"), collation_ci))
self.assertEqual(qs.count(), 2)

def test_collate_order_by_cs(self):
Expand Down
55 changes: 42 additions & 13 deletions tests/inspectdb/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,49 @@ def test_field_types(self):
Test introspection of various Django field types. In SingleStore,
db_collation is always included to the introspection result of a char field
"""
with connection.cursor() as cur:
cur.execute("SELECT @@collation_database")
results = cur.fetchall()
default_collation = results[0][0]

assertFieldType = self.make_field_type_asserter()
introspected_field_types = connection.features.introspected_field_types
char_field_type = introspected_field_types["CharField"]
# Inspecting Oracle DB doesn't produce correct results (#19884):
# - it reports fields as blank=True when they aren't.
if (
not connection.features.interprets_empty_strings_as_nulls
and char_field_type == "CharField"
):
assertFieldType("char_field", "models.CharField(max_length=10, db_collation='utf8mb4_general_ci')")
assertFieldType(
"char_field",
f"models.CharField(max_length=10, db_collation='{default_collation}')",
)
assertFieldType(
"null_char_field",
"models.CharField(max_length=10, db_collation='utf8mb4_general_ci', blank=True, null=True)",
)
assertFieldType("email_field", "models.CharField(max_length=254, db_collation='utf8mb4_general_ci')")
assertFieldType("file_field", "models.CharField(max_length=100, db_collation='utf8mb4_general_ci')")
assertFieldType("file_path_field", "models.CharField(max_length=100, db_collation='utf8mb4_general_ci')")
assertFieldType("slug_field", "models.CharField(max_length=50, db_collation='utf8mb4_general_ci')")
assertFieldType("text_field", "models.TextField(db_collation='utf8mb4_general_ci')")
assertFieldType("url_field", "models.CharField(max_length=200, db_collation='utf8mb4_general_ci')")
f"models.CharField(max_length=10, db_collation='{default_collation}', blank=True, null=True)",
)
assertFieldType(
"email_field",
f"models.CharField(max_length=254, db_collation='{default_collation}')",
)
assertFieldType(
"file_field",
f"models.CharField(max_length=100, db_collation='{default_collation}')",
)
assertFieldType(
"file_path_field",
f"models.CharField(max_length=100, db_collation='{default_collation}')",
)
assertFieldType(
"slug_field",
f"models.CharField(max_length=50, db_collation='{default_collation}')",
)
assertFieldType(
"text_field", f"models.TextField(db_collation='{default_collation}')"
)
assertFieldType(
"url_field",
f"models.CharField(max_length=200, db_collation='{default_collation}')",
)
if char_field_type == "TextField":
assertFieldType("char_field", "models.TextField()")
assertFieldType(
Expand All @@ -112,14 +135,20 @@ def test_field_types(self):
if introspected_field_types["GenericIPAddressField"] == "GenericIPAddressField":
assertFieldType("gen_ip_address_field", "models.GenericIPAddressField()")
elif not connection.features.interprets_empty_strings_as_nulls:
assertFieldType("gen_ip_address_field", "models.CharField(max_length=39, db_collation='utf8mb4_general_ci')")
assertFieldType(
"gen_ip_address_field",
f"models.CharField(max_length=39, db_collation='{default_collation}')",
)
assertFieldType(
"time_field", "models.%s()" % introspected_field_types["TimeField"]
)
if connection.features.has_native_uuid_field:
assertFieldType("uuid_field", "models.UUIDField()")
elif not connection.features.interprets_empty_strings_as_nulls:
assertFieldType("uuid_field", "models.CharField(max_length=32, db_collation='utf8mb4_general_ci')")
assertFieldType(
"uuid_field",
f"models.CharField(max_length=32, db_collation='{default_collation}')",
)

@skipUnlessDBFeature("can_introspect_json_field", "supports_json_field")
def test_json_field(self):
Expand Down
Loading