MCPcopy
hub / github.com/django/django / test_loading_squashed_erroneous

Method test_loading_squashed_erroneous

tests/migrations/test_loader.py:422–473  ·  view source on GitHub ↗

Tests loading a complex but erroneous set of squashed migrations

(self)

Source from the content-addressed store, hash-verified

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"},

Callers

nothing calls this directly

Calls 5

build_graphMethod · 0.95
record_appliedMethod · 0.95
MigrationLoaderClass · 0.90
MigrationRecorderClass · 0.90
assertRaisesMessageMethod · 0.80

Tested by

no test coverage detected