summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTyson Clugg <tyson@clugg.net>2015-08-11 17:51:01 +1000
committerMarkus Holtermann <info@markusholtermann.eu>2015-08-31 22:14:21 +1000
commite34226fc37dfa9eba89d913fd7ab8e95663b0d64 (patch)
tree63e150d83f4d88ae4a65975a42e8062edd3199ab /tests
parent235caabacc37278487d1107f6bbda90cc208cd64 (diff)
Fixed #25259 -- Added comments to header of generated migration files
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_writer.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index fb18f1cdb4..2b43fcf837 100644
--- a/tests/migrations/test_writer.py
+++ b/tests/migrations/test_writer.py
@@ -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.