import pytest from sentry_sdk.utils import BadDsn from src.backend import sentry class TestUseSentry: mock_env_var = "SENTRY_DSN" def test_use_sentry_dsn_is_set(self, monkeypatch): """Test that Sentry is enabled when the DSN is set.""" with pytest.raises(BadDsn): # Expected to raise BadDsn because of mock DSN monkeypatch.setenv(self.mock_env_var, "mock DSN") sentry.use_sentry(self.mock_env_var) def test_use_sentry_dsn_is_not_set(self, mocker): """Test that Sentry is not enabled when the DSN is not set, no exception should be raised but a warning should be logged. """ warning = mocker.spy(sentry.logger, "warning") sentry.use_sentry(self.mock_env_var) assert warning.called