diff options
| author | Mikuláš Poul <mikulas.poul@xelix.com> | 2025-03-23 15:30:24 +0000 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-04-16 10:20:49 +0200 |
| commit | 494d2dc316fc1d849b6a1af97575d293f856a84c (patch) | |
| tree | c4b1dffa9787ffbdb31d3549e1b262ded1ba1066 /tests/migrations | |
| parent | 5020a9d43a9ebd5f20f9a77e5fed424023facb15 (diff) | |
Fixed #36274 -- Added support for run_before and atomic in MigrationWriter.
Diffstat (limited to 'tests/migrations')
| -rw-r--r-- | tests/migrations/test_writer.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 6e9355d9bc..6afee23da2 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -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) |
