From e150bbd4d65b4b2c3897bdabdda94eba508747a2 Mon Sep 17 00:00:00 2001 From: John Giannelos Date: Tue, 3 Mar 2015 00:13:14 +0200 Subject: [1.8.x] Fixed #24427 -- Stopped writing migration files in dry run mode when merging. Also added display of migration to stdout when verbosity=3. Backport of 8758a63ddbbf7a2626bd84d50cfe83b477e8de0a from master --- tests/migrations/test_commands.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests') diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index f97ba05cb0..c8cf814e43 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -582,6 +582,49 @@ class MakeMigrationsTests(MigrationTestBase): self.assertFalse(os.path.exists(merge_file)) self.assertIn("Created new merge migration", output) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"}) + def test_makemigration_merge_dry_run(self): + """ + Makes sure that makemigrations respects --dry-run option when fixing + migration conflicts (#24427). + """ + out = six.StringIO() + call_command("makemigrations", "migrations", dry_run=True, merge=True, interactive=False, stdout=out) + merge_file = os.path.join(self.test_dir, '0003_merge.py') + self.assertFalse(os.path.exists(merge_file)) + output = force_text(out.getvalue()) + self.assertIn("Merging migrations", output) + self.assertIn("Branch 0002_second", output) + self.assertIn("Branch 0002_conflicting_second", output) + self.assertNotIn("Created new merge migration", output) + + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"}) + def test_makemigration_merge_dry_run_verbosity_3(self): + """ + Makes sure that `makemigrations --merge --dry-run` writes the merge + migration file to stdout with `verbosity == 3` (#24427). + """ + out = six.StringIO() + call_command("makemigrations", "migrations", dry_run=True, merge=True, interactive=False, + stdout=out, verbosity=3) + merge_file = os.path.join(self.test_dir, '0003_merge.py') + self.assertFalse(os.path.exists(merge_file)) + output = force_text(out.getvalue()) + self.assertIn("Merging migrations", output) + self.assertIn("Branch 0002_second", output) + self.assertIn("Branch 0002_conflicting_second", output) + self.assertNotIn("Created new merge migration", output) + + # Additional output caused by verbosity 3 + # The complete merge migration file that would be written + self.assertIn("# -*- coding: utf-8 -*-", output) + self.assertIn("class Migration(migrations.Migration):", output) + self.assertIn("dependencies = [", output) + self.assertIn("('migrations', '0002_second')", output) + self.assertIn("('migrations', '0002_conflicting_second')", output) + self.assertIn("operations = [", output) + self.assertIn("]", output) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_default"}) def test_makemigrations_dry_run(self): """ -- cgit v1.3