MCPcopy
hub / github.com/django/django / test_run_with_squashed

Method test_run_with_squashed

tests/migrations/test_executor.py:80–123  ·  view source on GitHub ↗

Tests running a squashed migration from zero (should ignore what it replaces)

(self)

Source from the content-addressed store, hash-verified

78 MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"}
79 )
80 def test_run_with_squashed(self):
81 """
82 Tests running a squashed migration from zero (should ignore what it
83 replaces)
84 """
85 executor = MigrationExecutor(connection)
86 # Check our leaf node is the squashed one
87 leaves = [
88 key for key in executor.loader.graph.leaf_nodes() if key[0] == "migrations"
89 ]
90 self.assertEqual(leaves, [("migrations", "0001_squashed_0002")])
91 # Check the plan
92 plan = executor.migration_plan([("migrations", "0001_squashed_0002")])
93 self.assertEqual(
94 plan,
95 [
96 (
97 executor.loader.graph.nodes["migrations", "0001_squashed_0002"],
98 False,
99 ),
100 ],
101 )
102 # Were the tables there before?
103 self.assertTableNotExists("migrations_author")
104 self.assertTableNotExists("migrations_book")
105 # Alright, let's try running it
106 executor.migrate([("migrations", "0001_squashed_0002")])
107 # Are the tables there now?
108 self.assertTableExists("migrations_author")
109 self.assertTableExists("migrations_book")
110 # Rebuild the graph to reflect the new DB state
111 executor.loader.build_graph()
112 # Alright, let's undo what we did. Should also just use squashed.
113 plan = executor.migration_plan([("migrations", None)])
114 self.assertEqual(
115 plan,
116 [
117 (executor.loader.graph.nodes["migrations", "0001_squashed_0002"], True),
118 ],
119 )
120 executor.migrate([("migrations", None)])
121 # Are the tables gone?
122 self.assertTableNotExists("migrations_author")
123 self.assertTableNotExists("migrations_book")
124
125 @override_settings(
126 MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"},

Callers

nothing calls this directly

Calls 7

migration_planMethod · 0.95
migrateMethod · 0.95
MigrationExecutorClass · 0.90
leaf_nodesMethod · 0.80
build_graphMethod · 0.80
assertTableNotExistsMethod · 0.45
assertTableExistsMethod · 0.45

Tested by

no test coverage detected