mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #36274 -- Added support for run_before and atomic in MigrationWriter.
This commit is contained in:
committed by
Sarah Boyce
parent
5020a9d43a
commit
494d2dc316
@@ -1178,3 +1178,42 @@ class WriterTests(SimpleTestCase):
|
||||
output = writer.as_string()
|
||||
self.assertEqual(output.count("import"), 1)
|
||||
self.assertIn("from django.db import migrations, models", output)
|
||||
|
||||
def test_run_before(self):
|
||||
for run_before, expected_run_before_str in [
|
||||
([("foo", "0001_bar")], " run_before = [('foo', '0001_bar')]\n"),
|
||||
(
|
||||
[("foo", "0001_bar"), ("foo", "0002_baz")],
|
||||
" run_before = [('foo', '0001_bar'), ('foo', '0002_baz')]\n",
|
||||
),
|
||||
]:
|
||||
with self.subTest(run_before=run_before):
|
||||
migration = type(
|
||||
"Migration",
|
||||
(migrations.Migration,),
|
||||
{"operations": [], "run_before": run_before},
|
||||
)
|
||||
writer = MigrationWriter(migration)
|
||||
output = writer.as_string()
|
||||
self.assertIn(expected_run_before_str, output)
|
||||
|
||||
def test_atomic_is_false(self):
|
||||
migration = type(
|
||||
"Migration",
|
||||
(migrations.Migration,),
|
||||
{"operations": [], "atomic": False},
|
||||
)
|
||||
writer = MigrationWriter(migration)
|
||||
output = writer.as_string()
|
||||
self.assertIn(" atomic = False\n", output)
|
||||
|
||||
def test_default_attributes(self):
|
||||
migration = type("Migration", (migrations.Migration,), {})
|
||||
writer = MigrationWriter(migration)
|
||||
output = writer.as_string()
|
||||
self.assertIn(" dependencies = [\n ]\n", output)
|
||||
self.assertIn(" operations = [\n ]\n", output)
|
||||
self.assertNotIn("atomic", output)
|
||||
self.assertNotIn("initial", output)
|
||||
self.assertNotIn("run_before", output)
|
||||
self.assertNotIn("replaces", output)
|
||||
|
||||
Reference in New Issue
Block a user