From e06c73d48fcf265ef9c4100bba2e6b7cb371d01f Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:02:50 +0000 Subject: [PATCH] fix(msteams): fail on a missing conversation id --- src/sentry/integrations/msteams/client.py | 2 +- .../integrations/msteams/test_client.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/sentry/integrations/msteams/client.py b/src/sentry/integrations/msteams/client.py index c6b572755dc7..be070867fbb2 100644 --- a/src/sentry/integrations/msteams/client.py +++ b/src/sentry/integrations/msteams/client.py @@ -81,7 +81,7 @@ def get_member_list( def get_user_conversation_id(self, user_id: str, tenant_id: str) -> str: data = {"members": [{"id": user_id}], "channelData": {"tenant": {"id": tenant_id}}} resp = self.post_mapping(self.CONVERSATION_URL, data=data) - return cast(str, resp.get("id")) + return cast(str, resp["id"]) def send_message(self, conversation_id: str, data: Mapping[str, object]) -> object: response: object = self.post(self.ACTIVITY_URL % conversation_id, data=data) diff --git a/tests/sentry/integrations/msteams/test_client.py b/tests/sentry/integrations/msteams/test_client.py index 95610f503eed..0ecff66bb7da 100644 --- a/tests/sentry/integrations/msteams/test_client.py +++ b/tests/sentry/integrations/msteams/test_client.py @@ -148,6 +148,28 @@ def test_skips_client_secret_expiry_gauge_when_invalid(self) -> None: get_token_data() mock_metrics.gauge.assert_not_called() + @responses.activate + def test_get_user_conversation_id(self) -> None: + responses.add( + responses.POST, + "https://smba.trafficmanager.net/amer/v3/conversations", + json={"id": "some_conversation_id"}, + ) + assert ( + self.msteams_client.get_user_conversation_id("user_id", "tenant_id") + == "some_conversation_id" + ) + + @responses.activate + def test_get_user_conversation_id_missing_id_raises(self) -> None: + responses.add( + responses.POST, + "https://smba.trafficmanager.net/amer/v3/conversations", + json={}, + ) + with pytest.raises(KeyError): + self.msteams_client.get_user_conversation_id("user_id", "tenant_id") + @responses.activate def test_simple(self) -> None: self.msteams_client.get_channel_list("foobar")