Tests loading a complex but erroneous set of squashed migrations
(self)
| 420 | } |
| 421 | ) |
| 422 | def test_loading_squashed_erroneous(self): |
| 423 | "Tests loading a complex but erroneous set of squashed migrations" |
| 424 | |
| 425 | loader = MigrationLoader(connection) |
| 426 | recorder = MigrationRecorder(connection) |
| 427 | self.addCleanup(recorder.flush) |
| 428 | |
| 429 | def num_nodes(): |
| 430 | plan = set(loader.graph.forwards_plan(("migrations", "7_auto"))) |
| 431 | return len(plan - loader.applied_migrations.keys()) |
| 432 | |
| 433 | # Empty database: use squashed migration |
| 434 | loader.build_graph() |
| 435 | self.assertEqual(num_nodes(), 5) |
| 436 | |
| 437 | # Starting at 1 or 2 should use the squashed migration too |
| 438 | self.record_applied(recorder, "migrations", "1_auto") |
| 439 | loader.build_graph() |
| 440 | self.assertEqual(num_nodes(), 4) |
| 441 | |
| 442 | self.record_applied(recorder, "migrations", "2_auto") |
| 443 | loader.build_graph() |
| 444 | self.assertEqual(num_nodes(), 3) |
| 445 | |
| 446 | # However, starting at 3 or 4, nonexistent migrations would be needed. |
| 447 | msg = ( |
| 448 | "Migration migrations.6_auto depends on nonexistent node " |
| 449 | "('migrations', '5_auto'). Django tried to replace migration " |
| 450 | "migrations.5_auto with any of [migrations.3_squashed_5] but wasn't able " |
| 451 | "to because some of the replaced migrations are already applied." |
| 452 | ) |
| 453 | |
| 454 | self.record_applied(recorder, "migrations", "3_auto") |
| 455 | with self.assertRaisesMessage(NodeNotFoundError, msg): |
| 456 | loader.build_graph() |
| 457 | |
| 458 | self.record_applied(recorder, "migrations", "4_auto") |
| 459 | with self.assertRaisesMessage(NodeNotFoundError, msg): |
| 460 | loader.build_graph() |
| 461 | |
| 462 | # Starting at 5 to 7 we are passed the squashed migrations |
| 463 | self.record_applied(recorder, "migrations", "5_auto") |
| 464 | loader.build_graph() |
| 465 | self.assertEqual(num_nodes(), 2) |
| 466 | |
| 467 | self.record_applied(recorder, "migrations", "6_auto") |
| 468 | loader.build_graph() |
| 469 | self.assertEqual(num_nodes(), 1) |
| 470 | |
| 471 | self.record_applied(recorder, "migrations", "7_auto") |
| 472 | loader.build_graph() |
| 473 | self.assertEqual(num_nodes(), 0) |
| 474 | |
| 475 | @override_settings( |
| 476 | MIGRATION_MODULES={"migrations": "migrations.test_migrations"}, |
nothing calls this directly
no test coverage detected