"""Unit tests for error handler functions.""" from sqlalchemy import exc from product_workflow import api from product_workflow.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) mocker.spy(error_handling, '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) error_handling.capture_exception.assert_called_with() context.g.ows.log.error.assert_called_with('DB error: {}'.format(message))