mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #33916 -- Added tests for serialization of enum.Flag in migrations.
This commit is contained in:
parent
0cbbed49f4
commit
08688bd7dd
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user