diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 6ec6d938b9e..bad8775d4eb 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -80,6 +80,11 @@ class IntEnum(enum.IntEnum): B = 2 +class IntFlagEnum(enum.IntFlag): + A = 1 + B = 2 + + class OperationWriterTests(SimpleTestCase): def test_empty_signature(self): operation = custom_migration_operations.operations.TestOperation() @@ -382,6 +387,33 @@ class WriterTests(SimpleTestCase): "default=migrations.test_writer.IntEnum['A'])", ) + def test_serialize_enum_flags(self): + self.assertSerializedResultEqual( + IntFlagEnum.A, + ( + "migrations.test_writer.IntFlagEnum['A']", + {"import migrations.test_writer"}, + ), + ) + self.assertSerializedResultEqual( + IntFlagEnum.B, + ( + "migrations.test_writer.IntFlagEnum['B']", + {"import migrations.test_writer"}, + ), + ) + field = models.IntegerField( + default=IntFlagEnum.A, choices=[(m.value, m) for m in IntFlagEnum] + ) + string = MigrationWriter.serialize(field)[0] + self.assertEqual( + string, + "models.IntegerField(choices=[" + "(1, migrations.test_writer.IntFlagEnum['A']), " + "(2, migrations.test_writer.IntFlagEnum['B'])], " + "default=migrations.test_writer.IntFlagEnum['A'])", + ) + def test_serialize_choices(self): class TextChoices(models.TextChoices): A = "A", "A value"