import importlib from unittest.mock import patch from ows_accounting.utils import sentry @patch('raven.Client', return_value='sentry_client') @patch('ows_accounting.config') def test_sentry_enabled(mock_config, mock_raven_client): """Test sentry.sentry_client is setup when config.SENTRY is set. """ mock_config.SENTRY = 'SENTRY' importlib.reload(sentry) assert sentry.sentry_client mock_raven_client.assert_called_with('SENTRY') assert sentry.sentry_client == 'sentry_client' @patch('raven.Client', return_value='sentry_client') @patch('ows_accounting.config') def test_sentry_disabled(mock_config, mock_raven_client): """Test sentry.sentry_client is not setup if config.SENTRY is not set. """ mock_config.SENTRY = None importlib.reload(sentry) assert not sentry.sentry_client assert mock_raven_client.call_count == 0