Clarify SQLite can't drop foreign key constraints (#123898)

This commit is contained in:
Erik Montnemery 2024-08-14 14:04:53 +02:00 committed by GitHub
parent ea7e88d000
commit e050d187c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 90 additions and 6 deletions

View file

@ -1053,3 +1053,51 @@ def test_delete_foreign_key_violations_unsupported_engine(
RuntimeError, match="_delete_foreign_key_violations not supported for sqlite"
):
migration._delete_foreign_key_violations(session_maker, engine, "", "", "", "")
def test_drop_foreign_key_constraints_unsupported_engine(
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test calling _drop_foreign_key_constraints with an unsupported engine."""
connection = Mock()
connection.execute = Mock(side_effect=InternalError(None, None, None))
session = Mock()
session.connection = Mock(return_value=connection)
instance = Mock()
instance.get_session = Mock(return_value=session)
engine = Mock()
engine.dialect = Mock()
engine.dialect.name = "sqlite"
session_maker = Mock(return_value=session)
with pytest.raises(
RuntimeError, match="_drop_foreign_key_constraints not supported for sqlite"
):
migration._drop_foreign_key_constraints(session_maker, engine, "", "")
def test_update_states_table_with_foreign_key_options_unsupported_engine(
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test calling function with an unsupported engine.
This tests _update_states_table_with_foreign_key_options.
"""
connection = Mock()
connection.execute = Mock(side_effect=InternalError(None, None, None))
session = Mock()
session.connection = Mock(return_value=connection)
instance = Mock()
instance.get_session = Mock(return_value=session)
engine = Mock()
engine.dialect = Mock()
engine.dialect.name = "sqlite"
session_maker = Mock(return_value=session)
with pytest.raises(
RuntimeError,
match="_update_states_table_with_foreign_key_options not supported for sqlite",
):
migration._update_states_table_with_foreign_key_options(session_maker, engine)