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_db_check_sqlalchemy_error(mocker, db):
engine_connect = mocker.patch.object(db.engine, "connect")
engine_connect.side_effect = SQLAlchemyError
errors = checks.check_database_connected(db)
assert len(errors) == 1
assert errors[0].id == health.ERROR_SQLALCHEMY_EXCEPTION
def test_db_check_dbapi_error(mocker, db):
exception = DBAPIError.instance("", [], Exception(), Exception)
engine_connect = mocker.patch.object(db.engine, "connect")
engine_connect.side_effect = exception
errors = checks.check_database_connected(db)
assert len(errors) == 1
assert errors[0].id == health.ERROR_DB_API_EXCEPTION
def test_db_check_success(db):
errors = checks.check_database_connected(db)
assert errors == []