MCPcopy
hub / github.com/django/django / test_run

Method test_run

tests/migrations/test_executor.py:39–75  ·  view source on GitHub ↗

Tests running a simple set of migrations.

(self)

Source from the content-addressed store, hash-verified

37
38 @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
39 def test_run(self):
40 """
41 Tests running a simple set of migrations.
42 """
43 executor = MigrationExecutor(connection)
44 # Let's look at the plan first and make sure it's up to scratch
45 plan = executor.migration_plan([("migrations", "0002_second")])
46 self.assertEqual(
47 plan,
48 [
49 (executor.loader.graph.nodes["migrations", "0001_initial"], False),
50 (executor.loader.graph.nodes["migrations", "0002_second"], False),
51 ],
52 )
53 # Were the tables there before?
54 self.assertTableNotExists("migrations_author")
55 self.assertTableNotExists("migrations_book")
56 # Alright, let's try running it
57 executor.migrate([("migrations", "0002_second")])
58 # Are the tables there now?
59 self.assertTableExists("migrations_author")
60 self.assertTableExists("migrations_book")
61 # Rebuild the graph to reflect the new DB state
62 executor.loader.build_graph()
63 # Alright, let's undo what we did
64 plan = executor.migration_plan([("migrations", None)])
65 self.assertEqual(
66 plan,
67 [
68 (executor.loader.graph.nodes["migrations", "0002_second"], True),
69 (executor.loader.graph.nodes["migrations", "0001_initial"], True),
70 ],
71 )
72 executor.migrate([("migrations", None)])
73 # Are the tables gone?
74 self.assertTableNotExists("migrations_author")
75 self.assertTableNotExists("migrations_book")
76
77 @override_settings(
78 MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected