|
@@ -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.
|