summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-04-21 09:59:01 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-04-21 10:00:09 +0200
commit765b96734c374ae8612720a6f71c0094430e6cf7 (patch)
treefec8667eda058c988201613c9f6324c20305b77a /tests/schema
parent8a6c0203c4e92908c2b26ba54feba4ce7e76d081 (diff)
downloaddjango-765b96734c374ae8612720a6f71c0094430e6cf7.tar.gz
Added SchemaTests._add_ci_collation() hook.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py41
1 files changed, 17 insertions, 24 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 5a03ac6fd5..58c87904f7 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1293,17 +1293,8 @@ class SchemaTests(TransactionTestCase):
with self.assertRaisesMessage(DataError, msg):
editor.alter_field(ArrayModel, old_field, new_field, strict=True)
- @isolate_apps("schema")
- @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific")
- @skipUnlessDBFeature(
- "supports_collation_on_charfield",
- "supports_non_deterministic_collations",
- )
- def test_db_collation_arrayfield(self):
- from django.contrib.postgres.fields import ArrayField
-
+ def _add_ci_collation(self):
ci_collation = "case_insensitive"
- cs_collation = "en-x-icu"
def drop_collation():
with connection.cursor() as cursor:
@@ -1311,10 +1302,23 @@ class SchemaTests(TransactionTestCase):
with connection.cursor() as cursor:
cursor.execute(
- f"CREATE COLLATION IF NOT EXISTS {ci_collation} (provider = icu, "
- f"locale = 'und-u-ks-level2', deterministic = false)"
+ f"CREATE COLLATION IF NOT EXISTS {ci_collation} (provider=icu, "
+ f"locale='und-u-ks-level2', deterministic=false)"
)
self.addCleanup(drop_collation)
+ return ci_collation
+
+ @isolate_apps("schema")
+ @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific")
+ @skipUnlessDBFeature(
+ "supports_collation_on_charfield",
+ "supports_non_deterministic_collations",
+ )
+ def test_db_collation_arrayfield(self):
+ from django.contrib.postgres.fields import ArrayField
+
+ ci_collation = self._add_ci_collation()
+ cs_collation = "en-x-icu"
class ArrayModel(Model):
field = ArrayField(CharField(max_length=16, db_collation=ci_collation))
@@ -1349,18 +1353,7 @@ class SchemaTests(TransactionTestCase):
"supports_non_deterministic_collations",
)
def test_unique_with_collation_charfield(self):
- ci_collation = "case_insensitive"
-
- def drop_collation():
- with connection.cursor() as cursor:
- cursor.execute(f"DROP COLLATION IF EXISTS {ci_collation}")
-
- with connection.cursor() as cursor:
- cursor.execute(
- f"CREATE COLLATION IF NOT EXISTS {ci_collation} (provider = icu, "
- f"locale = 'und-u-ks-level2', deterministic = false)"
- )
- self.addCleanup(drop_collation)
+ ci_collation = self._add_ci_collation()
class CiCharModel(Model):
field = CharField(max_length=16, db_collation=ci_collation, unique=True)