"""Tests for the Sentry Connector.""" from unittest.mock import patch from oto import response from notifications.connectors import sentry @patch('notifications.connectors.sentry.sentry_sdk.init') @patch('notifications.connectors.sentry.config') def test_sentry_enabled(mock_config, mock_sentry_init): """Test sentry client is setup when config.SENTRY is set.""" mock_config.SENTRY = 'SENTRY' result = sentry.get_client() assert result is True mock_sentry_init.assert_called_with(dsn='SENTRY') @patch('notifications.connectors.sentry.sentry_sdk.init') @patch('notifications.connectors.sentry.config') def test_sentry_disabled(mock_config, mock_sentry_init): """Test sentry client not initialized when config.SENTRY is None.""" mock_config.SENTRY = None result = sentry.get_client() assert result is False mock_sentry_init.assert_not_called() @patch('notifications.connectors.sentry.sentry_sdk.capture_message') def test_send_response_to_sentry(mock_capture_message): """Test sending an error message to Sentry.""" error_response = response.Response( message='response message', errors={'error_code': 'error_message'}, status=204) sentry_message = 'sentry message' sentry.send_response_to_sentry(error_response, sentry_message) mock_capture_message.assert_called_with( message=sentry_message, level='error', extra={ 'message': error_response.message, 'errors': error_response.errors, 'status': error_response.status})