mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #25259 -- Added comments to header of generated migration files
This commit is contained in:
committed by
Markus Holtermann
parent
235caabacc
commit
e34226fc37
@@ -12,13 +12,14 @@ import unittest
|
||||
import custom_migration_operations.more_operations
|
||||
import custom_migration_operations.operations
|
||||
|
||||
from django import get_version
|
||||
from django.conf import settings
|
||||
from django.core.validators import EmailValidator, RegexValidator
|
||||
from django.db import migrations, models
|
||||
from django.db.migrations.writer import (
|
||||
MigrationWriter, OperationWriter, SettingsReference,
|
||||
)
|
||||
from django.test import SimpleTestCase, ignore_warnings
|
||||
from django.test import SimpleTestCase, ignore_warnings, mock
|
||||
from django.utils import datetime_safe, six
|
||||
from django.utils._os import upath
|
||||
from django.utils.deconstruct import deconstructible
|
||||
@@ -525,6 +526,27 @@ class WriterTests(SimpleTestCase):
|
||||
output
|
||||
)
|
||||
|
||||
def test_migration_file_header_comments(self):
|
||||
"""
|
||||
Test comments at top of file.
|
||||
"""
|
||||
migration = type(str("Migration"), (migrations.Migration,), {
|
||||
"operations": []
|
||||
})
|
||||
dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=utc)
|
||||
with mock.patch('django.db.migrations.writer.now', lambda: dt):
|
||||
writer = MigrationWriter(migration)
|
||||
output = writer.as_string().decode('utf-8')
|
||||
|
||||
self.assertTrue(
|
||||
output.startswith(
|
||||
"# -*- coding: utf-8 -*-\n"
|
||||
"# Generated by Django %(version)s on 2015-07-31 04:40\n" % {
|
||||
'version': get_version(),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def test_models_import_omitted(self):
|
||||
"""
|
||||
django.db.models shouldn't be imported if unused.
|
||||
|
||||
Reference in New Issue
Block a user