mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #24155 -- Maintained kwargs and import order in migration writer
Thanks Tomas Dobrovolny for the report and Tim Graham for the review.
This commit is contained in:
parent
bd691f4586
commit
7f20041bca
2 changed files with 37 additions and 7 deletions
|
@ -216,7 +216,15 @@ class WriterTests(TestCase):
|
|||
|
||||
def test_serialize_fields(self):
|
||||
self.assertSerializedFieldEqual(models.CharField(max_length=255))
|
||||
self.assertSerializedResultEqual(
|
||||
models.CharField(max_length=255),
|
||||
("models.CharField(max_length=255)", {"from django.db import models"})
|
||||
)
|
||||
self.assertSerializedFieldEqual(models.TextField(null=True, blank=True))
|
||||
self.assertSerializedResultEqual(
|
||||
models.TextField(null=True, blank=True),
|
||||
("models.TextField(blank=True, null=True)", {'from django.db import models'})
|
||||
)
|
||||
|
||||
def test_serialize_settings(self):
|
||||
self.assertSerializedEqual(SettingsReference(settings.AUTH_USER_MODEL, "AUTH_USER_MODEL"))
|
||||
|
@ -419,6 +427,26 @@ class WriterTests(TestCase):
|
|||
result['custom_migration_operations'].more_operations.TestOperation
|
||||
)
|
||||
|
||||
def test_sorted_imports(self):
|
||||
"""
|
||||
#24155 - Tests ordering of imports.
|
||||
"""
|
||||
migration = type(str("Migration"), (migrations.Migration,), {
|
||||
"operations": [
|
||||
migrations.AddField("mymodel", "myfield", models.DateTimeField(
|
||||
default=datetime.datetime(2012, 1, 1, 1, 1, tzinfo=utc),
|
||||
)),
|
||||
]
|
||||
})
|
||||
writer = MigrationWriter(migration)
|
||||
output = writer.as_string().decode('utf-8')
|
||||
self.assertIn(
|
||||
"import datetime\n"
|
||||
"from django.db import migrations, models\n"
|
||||
"from django.utils.timezone import utc\n",
|
||||
output
|
||||
)
|
||||
|
||||
def test_deconstruct_class_arguments(self):
|
||||
# Yes, it doesn't make sense to use a class as a default for a
|
||||
# CharField. It does make sense for custom fields though, for example
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue