From 9e17cc062c62eec1177aaf65ebebba43e074cde2 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 6 Jun 2021 14:45:36 -0400 Subject: [PATCH] Refs #24900 -- Added MigrationLoader test for applying squashed migrations. --- tests/migrations/test_loader.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py index 3c4f44aa5e..03a98506e3 100644 --- a/tests/migrations/test_loader.py +++ b/tests/migrations/test_loader.py @@ -485,6 +485,27 @@ class LoaderTests(TestCase): } self.assertEqual(plan, expected_plan) + # Load with nothing applied and migrate to a replaced migration. + # Not possible if loader.replace_migrations is True (default). + loader.build_graph() + msg = "Node ('app1', '3_auto') not a valid node" + with self.assertRaisesMessage(NodeNotFoundError, msg): + loader.graph.forwards_plan(('app1', '3_auto')) + # Possible if loader.replace_migrations is False. + loader.replace_migrations = False + loader.build_graph() + plan = set(loader.graph.forwards_plan(('app1', '3_auto'))) + plan = plan - loader.applied_migrations.keys() + expected_plan = { + ('app1', '1_auto'), + ('app2', '1_auto'), + ('app2', '2_auto'), + ('app1', '2_auto'), + ('app1', '3_auto'), + } + self.assertEqual(plan, expected_plan) + loader.replace_migrations = True + # Fake-apply a few from app1: unsquashes migration in app1. self.record_applied(recorder, 'app1', '1_auto') self.record_applied(recorder, 'app1', '2_auto')