"""Unit tests for error handler functions.""" from sqlalchemy import exc from reporting import api from reporting.utils import error_handling def test_log_db_exception(context, mocker, valid_get_header): """Test that the exception is sent to Sentry and Loggly.""" message = 'something did not work' exception = exc.SQLAlchemyError(message) mock_capture = mocker.patch('sentry_sdk.capture_exception') with context, api.app.test_request_context(headers=valid_get_header): mocker.spy(context.g.ows.log, 'error') error_handling.log_db_exception(exception) mock_capture.assert_called_with(exception) context.g.ows.log.error.assert_called_with('DB error: {}'.format(message))