summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py39
1 files changed, 39 insertions, 0 deletions
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())