MCPcopy
hub / github.com/django/django / test_remove_field

Method test_remove_field

tests/migrations/test_operations.py:2042–2075  ·  view source on GitHub ↗

Tests the RemoveField operation.

(self)

Source from the content-addressed store, hash-verified

2040 self.apply_operations("test_rmflmmwt", project_state, operations=operations)
2041
2042 def test_remove_field(self):
2043 """
2044 Tests the RemoveField operation.
2045 """
2046 project_state = self.set_up_test_model("test_rmfl")
2047 # Test the state alteration
2048 operation = migrations.RemoveField("Pony", "pink")
2049 self.assertEqual(operation.describe(), "Remove field pink from Pony")
2050 self.assertEqual(
2051 operation.formatted_description(), "- Remove field pink from Pony"
2052 )
2053 self.assertEqual(operation.migration_name_fragment, "remove_pony_pink")
2054 new_state = project_state.clone()
2055 operation.state_forwards("test_rmfl", new_state)
2056 self.assertEqual(len(new_state.models["test_rmfl", "pony"].fields), 4)
2057 # Test the database alteration
2058 self.assertColumnExists("test_rmfl_pony", "pink")
2059 with (
2060 connection.schema_editor() as editor,
2061 CaptureQueriesContext(connection) as ctx,
2062 ):
2063 operation.database_forwards("test_rmfl", editor, project_state, new_state)
2064 self.assertGreater(len(ctx.captured_queries), 0)
2065 self.assertNotIn("CASCADE", ctx.captured_queries[-1]["sql"])
2066 self.assertColumnNotExists("test_rmfl_pony", "pink")
2067 # And test reversal
2068 with connection.schema_editor() as editor:
2069 operation.database_backwards("test_rmfl", editor, new_state, project_state)
2070 self.assertColumnExists("test_rmfl_pony", "pink")
2071 # And deconstruction
2072 definition = operation.deconstruct()
2073 self.assertEqual(definition[0], "RemoveField")
2074 self.assertEqual(definition[1], [])
2075 self.assertEqual(definition[2], {"model_name": "Pony", "name": "pink"})
2076
2077 def test_remove_fk(self):
2078 """

Callers

nothing calls this directly

Calls 12

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
assertColumnExistsMethod · 0.45
assertColumnNotExistsMethod · 0.45

Tested by

no test coverage detected