"""Test integration of an app with sentry.""" import importlib from unittest.mock import patch from salessheets.connectors import sentry @patch('sentry_sdk.init', return_value='sentry_init') @patch('sentry_sdk.client', return_value='sentry_client') @patch('salessheets.config') def test_sentry_enabled(mock_config, mock_sentry_client, mock_sentry_init): """Test sentry client with config. Test sentry.sentry_client is set up when config.SENTRY is set. """ mock_config.SENTRY_DSN = 'SENTRY' importlib.reload(sentry) mock_sentry_init.assert_called() assert sentry.sentry_client @patch('sentry_sdk.client', return_value='sentry_client') @patch('salessheets.config') def test_sentry_disabled(mock_config, mock_sentry_client): """Test sentry client without config. Test sentry.sentry_client is not setup if config.SENTRY is not set. """ mock_config.SENTRY_DSN = None importlib.reload(sentry) assert not sentry.sentry_client assert mock_sentry_client.call_count == 0