Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_migrations_applied_success(mocker, db, migrate):
get_heads = mocker.patch(
"alembic.script.ScriptDirectory.get_heads", return_value=("17164a7d1c2e",)
)
get_current_heads = mocker.patch(
"alembic.migration.MigrationContext.get_current_heads",
return_value=("17164a7d1c2e",),
)
errors = checks.check_migrations_applied(migrate)
assert get_heads.called
assert get_current_heads.called
assert len(errors) == 0
def test_check_migrations_applied_cannot_check_migrations(
exception, mocker, db, migrate
):
engine_connect = mocker.patch.object(db.engine, "connect")
engine_connect.side_effect = exception
errors = checks.check_migrations_applied(migrate)
assert len(errors) == 1
assert errors[0].id == health.INFO_CANT_CHECK_MIGRATIONS
def test_check_migrations_applied_unapplied_migrations(mocker, db, migrate):
get_heads = mocker.patch(
"alembic.script.ScriptDirectory.get_heads", return_value=("7f447c94347a",)
)
get_current_heads = mocker.patch(
"alembic.migration.MigrationContext.get_current_heads",
return_value=("73d96d3120ff",),
)
errors = checks.check_migrations_applied(migrate)
assert get_heads.called
assert get_current_heads.called
assert len(errors) == 1
assert errors[0].id == health.WARNING_UNAPPLIED_MIGRATION