mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #24278 -- Fixed serialization of migration operations.
Fixed MigrationWriter.serialize() to correctly handle migration operations by utilizing OperationWriter. Thanks Piotr Maliński for the report.
This commit is contained in:
parent
d597174bd4
commit
e8e4f978dd
4 changed files with 54 additions and 0 deletions
|
@ -81,6 +81,27 @@ class OperationWriterTests(SimpleTestCase):
|
|||
'),'
|
||||
)
|
||||
|
||||
def test_nested_args_signature(self):
|
||||
operation = custom_migration_operations.operations.ArgsOperation(
|
||||
custom_migration_operations.operations.ArgsOperation(1, 2),
|
||||
custom_migration_operations.operations.KwargsOperation(kwarg1=3, kwarg2=4)
|
||||
)
|
||||
buff, imports = OperationWriter(operation, indentation=0).serialize()
|
||||
self.assertEqual(imports, {'import custom_migration_operations.operations'})
|
||||
self.assertEqual(
|
||||
buff,
|
||||
'custom_migration_operations.operations.ArgsOperation(\n'
|
||||
' arg1=custom_migration_operations.operations.ArgsOperation(\n'
|
||||
' arg1=1,\n'
|
||||
' arg2=2,\n'
|
||||
' ),\n'
|
||||
' arg2=custom_migration_operations.operations.KwargsOperation(\n'
|
||||
' kwarg1=3,\n'
|
||||
' kwarg2=4,\n'
|
||||
' ),\n'
|
||||
'),'
|
||||
)
|
||||
|
||||
def test_multiline_args_signature(self):
|
||||
operation = custom_migration_operations.operations.ArgsOperation("test\n arg1", "test\narg2")
|
||||
buff, imports = OperationWriter(operation, indentation=0).serialize()
|
||||
|
@ -107,6 +128,29 @@ class OperationWriterTests(SimpleTestCase):
|
|||
'),'
|
||||
)
|
||||
|
||||
def test_nested_operation_expand_args_signature(self):
|
||||
operation = custom_migration_operations.operations.ExpandArgsOperation(
|
||||
arg=[
|
||||
custom_migration_operations.operations.KwargsOperation(
|
||||
kwarg1=1,
|
||||
kwarg2=2,
|
||||
),
|
||||
]
|
||||
)
|
||||
buff, imports = OperationWriter(operation, indentation=0).serialize()
|
||||
self.assertEqual(imports, {'import custom_migration_operations.operations'})
|
||||
self.assertEqual(
|
||||
buff,
|
||||
'custom_migration_operations.operations.ExpandArgsOperation(\n'
|
||||
' arg=[\n'
|
||||
' custom_migration_operations.operations.KwargsOperation(\n'
|
||||
' kwarg1=1,\n'
|
||||
' kwarg2=2,\n'
|
||||
' ),\n'
|
||||
' ],\n'
|
||||
'),'
|
||||
)
|
||||
|
||||
|
||||
class WriterTests(TestCase):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue