MCPcopy
hub / github.com/django/django / test_alter_model_table

Method test_alter_model_table

tests/migrations/test_operations.py:2094–2133  ·  view source on GitHub ↗

Tests the AlterModelTable operation.

(self)

Source from the content-addressed store, hash-verified

2092 self.assertColumnExists("test_rfk_rider", "pony_id")
2093
2094 def test_alter_model_table(self):
2095 """
2096 Tests the AlterModelTable operation.
2097 """
2098 project_state = self.set_up_test_model("test_almota")
2099 # Test the state alteration
2100 operation = migrations.AlterModelTable("Pony", "test_almota_pony_2")
2101 self.assertEqual(
2102 operation.describe(), "Rename table for Pony to test_almota_pony_2"
2103 )
2104 self.assertEqual(
2105 operation.formatted_description(),
2106 "~ Rename table for Pony to test_almota_pony_2",
2107 )
2108 self.assertEqual(operation.migration_name_fragment, "alter_pony_table")
2109 new_state = project_state.clone()
2110 operation.state_forwards("test_almota", new_state)
2111 self.assertEqual(
2112 new_state.models["test_almota", "pony"].options["db_table"],
2113 "test_almota_pony_2",
2114 )
2115 # Test the database alteration
2116 self.assertTableExists("test_almota_pony")
2117 self.assertTableNotExists("test_almota_pony_2")
2118 with connection.schema_editor() as editor:
2119 operation.database_forwards("test_almota", editor, project_state, new_state)
2120 self.assertTableNotExists("test_almota_pony")
2121 self.assertTableExists("test_almota_pony_2")
2122 # And test reversal
2123 with connection.schema_editor() as editor:
2124 operation.database_backwards(
2125 "test_almota", editor, new_state, project_state
2126 )
2127 self.assertTableExists("test_almota_pony")
2128 self.assertTableNotExists("test_almota_pony_2")
2129 # And deconstruction
2130 definition = operation.deconstruct()
2131 self.assertEqual(definition[0], "AlterModelTable")
2132 self.assertEqual(definition[1], [])
2133 self.assertEqual(definition[2], {"name": "Pony", "table": "test_almota_pony_2"})
2134
2135 def test_alter_model_table_none(self):
2136 """

Callers

nothing calls this directly

Calls 11

describeMethod · 0.95
state_forwardsMethod · 0.95
database_forwardsMethod · 0.95
database_backwardsMethod · 0.95
deconstructMethod · 0.95
formatted_descriptionMethod · 0.80
schema_editorMethod · 0.80
set_up_test_modelMethod · 0.45
cloneMethod · 0.45
assertTableExistsMethod · 0.45
assertTableNotExistsMethod · 0.45

Tested by

no test coverage detected