|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Any |
| 4 | +from unittest.mock import MagicMock, patch |
| 5 | + |
| 6 | +import orjson |
| 7 | + |
| 8 | +from sentry.testutils.cases import APITestCase |
| 9 | + |
| 10 | + |
| 11 | +def mock_seer_response(data: dict[str, Any]) -> MagicMock: |
| 12 | + response = MagicMock() |
| 13 | + response.status = 200 |
| 14 | + response.data = orjson.dumps(data) |
| 15 | + return response |
| 16 | + |
| 17 | + |
| 18 | +class OrganizationSupergroupDetailsEndpointTest(APITestCase): |
| 19 | + endpoint = "sentry-api-0-organization-supergroup-details" |
| 20 | + |
| 21 | + def setUp(self): |
| 22 | + super().setUp() |
| 23 | + self.login_as(self.user) |
| 24 | + |
| 25 | + @patch( |
| 26 | + "sentry.seer.supergroups.endpoints.organization_supergroup_details.make_supergroups_get_request" |
| 27 | + ) |
| 28 | + def test_get_supergroup_details(self, mock_seer): |
| 29 | + mock_seer.return_value = mock_seer_response( |
| 30 | + {"id": 1, "title": "NullPointerException in auth", "group_ids": [10, 20]} |
| 31 | + ) |
| 32 | + |
| 33 | + with self.feature("organizations:top-issues-ui"): |
| 34 | + response = self.get_success_response(self.organization.slug, "1") |
| 35 | + |
| 36 | + assert response.data["id"] == 1 |
| 37 | + assert response.data["title"] == "NullPointerException in auth" |
| 38 | + assert response.data["group_ids"] == [10, 20] |
| 39 | + |
| 40 | + @patch( |
| 41 | + "sentry.seer.supergroups.endpoints.organization_supergroup_details.make_supergroups_get_request" |
| 42 | + ) |
| 43 | + def test_rca_source_defaults_to_explorer(self, mock_seer): |
| 44 | + mock_seer.return_value = mock_seer_response({"id": 1, "title": "test"}) |
| 45 | + |
| 46 | + with self.feature("organizations:top-issues-ui"): |
| 47 | + self.get_success_response(self.organization.slug, "1") |
| 48 | + |
| 49 | + body = mock_seer.call_args.args[0] |
| 50 | + assert body["rca_source"] == "EXPLORER" |
| 51 | + |
| 52 | + @patch( |
| 53 | + "sentry.seer.supergroups.endpoints.organization_supergroup_details.make_supergroups_get_request" |
| 54 | + ) |
| 55 | + def test_rca_source_lightweight_when_flag_enabled(self, mock_seer): |
| 56 | + mock_seer.return_value = mock_seer_response({"id": 1, "title": "test"}) |
| 57 | + |
| 58 | + with self.feature( |
| 59 | + { |
| 60 | + "organizations:top-issues-ui": True, |
| 61 | + "organizations:supergroups-lightweight-rca-clustering-read": True, |
| 62 | + } |
| 63 | + ): |
| 64 | + self.get_success_response(self.organization.slug, "1") |
| 65 | + |
| 66 | + body = mock_seer.call_args.args[0] |
| 67 | + assert body["rca_source"] == "LIGHTWEIGHT" |
0 commit comments