diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-08-02 11:44:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-02 11:44:26 +0200 |
| commit | ab1955a05e369337c3eaad1a2d34de346932179d (patch) | |
| tree | 01854839ca59cb667cc8eb6ffada5c3ae284913f /tests | |
| parent | 89e695a69b16b8c0e720169b3ca4852cfd0c485f (diff) | |
Fixed #33881 -- Added support for database collations to ArrayField(Char/TextFields).
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema/tests.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 2868f59501..0702b54135 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -1236,6 +1236,55 @@ 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 + + ci_collation = "case_insensitive" + cs_collation = "en-x-icu" + + 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) + + class ArrayModel(Model): + field = ArrayField(CharField(max_length=16, db_collation=ci_collation)) + + class Meta: + app_label = "schema" + + # Create the table. + with connection.schema_editor() as editor: + editor.create_model(ArrayModel) + self.isolated_local_models = [ArrayModel] + self.assertEqual( + self.get_column_collation(ArrayModel._meta.db_table, "field"), + ci_collation, + ) + # Alter collation. + old_field = ArrayModel._meta.get_field("field") + new_field_cs = ArrayField(CharField(max_length=16, db_collation=cs_collation)) + new_field_cs.set_attributes_from_name("field") + new_field_cs.model = ArrayField + with connection.schema_editor() as editor: + editor.alter_field(ArrayModel, old_field, new_field_cs, strict=True) + self.assertEqual( + self.get_column_collation(ArrayModel._meta.db_table, "field"), + cs_collation, + ) + def test_alter_textfield_to_null(self): """ #24307 - Should skip an alter statement on databases with |
