From d18810131995dac63f9d89b0beaeadfc935130aa Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 16 Nov 2014 18:42:23 +0100 Subject: Fixed #23799 -- Made makemigrations respect --no-optimize. Thanks to yamila-moreno for the idea of a skip message. --- tests/migrations/test_commands.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests') diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index f4e3878d17..83826e819d 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -543,3 +543,42 @@ class MakeMigrationsTests(MigrationTestBase): content = cmd("0002", migration_name_0002, "--empty") self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content) self.assertIn("operations=[\n]", content) + + +class SquashMigrationsTest(MigrationTestBase): + """ + Tests running the squashmigrations command. + """ + + path = "migrations/test_migrations/0001_squashed_0002_second.py" + + def tearDown(self): + if os.path.exists(self.path): + os.remove(self.path) + + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) + def test_squashmigrations_squashes(self): + """ + Tests that squashmigrations squashes migrations. + """ + call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=0) + self.assertTrue(os.path.exists(self.path)) + + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) + def test_squashmigrations_optimizes(self): + """ + Tests that squashmigrations optimizes operations. + """ + out = six.StringIO() + call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, stdout=out) + self.assertIn("Optimized from 7 operations to 5 operations.", out.getvalue()) + + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) + def test_ticket_23799_squashmigrations_no_optimize(self): + """ + Makes sure that squashmigrations --no-optimize really doesn't optimize operations. + """ + out = six.StringIO() + call_command("squashmigrations", "migrations", "0002", + interactive=False, verbosity=1, no_optimize=True, stdout=out) + self.assertIn("Skipping optimization", out.getvalue()) -- cgit v1.3