Ticket #34219: test-34219.diff

File test-34219.diff, 1.9 KB (added by Mariusz Felisiak, 23 months ago)

Regression test.

  • tests/schema/tests.py

    diff --git a/tests/schema/tests.py b/tests/schema/tests.py
    index fee5ca9d2b..9b2b512c1b 100644
    a b class SchemaTests(TransactionTestCase):  
    49504950            editor.alter_field(Author, new_field, old_field, strict=True)
    49514951        self.assertIsNone(self.get_column_collation(Author._meta.db_table, "name"))
    49524952
     4953    @skipUnlessDBFeature("supports_collation_on_charfield")
     4954    def test_alter_field_type_preserve_db_collation(self):
     4955        collation = connection.features.test_collations.get("non_default")
     4956        if not collation:
     4957            self.skipTest("Language collations are not supported.")
     4958
     4959        with connection.schema_editor() as editor:
     4960            editor.create_model(Author)
     4961
     4962        old_field = Author._meta.get_field("name")
     4963        new_field = CharField(max_length=255, db_collation=collation)
     4964        new_field.set_attributes_from_name("name")
     4965        new_field.model = Author
     4966        with connection.schema_editor() as editor:
     4967            editor.alter_field(Author, old_field, new_field, strict=True)
     4968        self.assertEqual(
     4969            self.get_column_collation(Author._meta.db_table, "name"),
     4970            collation,
     4971        )
     4972        # Changing a field type should preserve the collation.
     4973        old_field = new_field
     4974        new_field = CharField(max_length=511, db_collation=collation)
     4975        new_field.set_attributes_from_name("name")
     4976        new_field.model = Author
     4977        with connection.schema_editor() as editor:
     4978            editor.alter_field(Author, new_field, old_field, strict=True)
     4979        # Collation is preserved.
     4980        self.assertEqual(
     4981            self.get_column_collation(Author._meta.db_table, "name"),
     4982            collation,
     4983        )
     4984
    49534985    @skipUnlessDBFeature("supports_collation_on_charfield")
    49544986    def test_alter_primary_key_db_collation(self):
    49554987        collation = connection.features.test_collations.get("non_default")
Back to Top