|
4 | 4 | from urllib.parse import parse_qs, quote, urlencode, urlparse |
5 | 5 |
|
6 | 6 | import orjson |
| 7 | +import pytest |
7 | 8 | import responses |
8 | 9 | from django.core.cache import cache |
9 | 10 | from django.test import override_settings |
|
21 | 22 | ) |
22 | 23 | from sentry.integrations.types import ExternalProviders |
23 | 24 | from sentry.models.repository import Repository |
| 25 | +from sentry.shared_integrations.exceptions import ApiForbiddenError, IntegrationConfigurationError |
24 | 26 | from sentry.silo.base import SiloMode |
25 | 27 | from sentry.silo.util import PROXY_BASE_PATH, PROXY_OI_HEADER, PROXY_SIGNATURE_HEADER |
26 | 28 | from sentry.testutils.cases import IntegrationTestCase |
|
29 | 31 | from sentry.testutils.silo import assume_test_silo_mode, control_silo_test |
30 | 32 | from sentry.users.models.identity import Identity, IdentityProvider, IdentityStatus |
31 | 33 | from sentry.users.services.user.serial import serialize_rpc_user |
| 34 | +from sentry.utils import json |
32 | 35 | from tests.sentry.integrations.test_helpers import add_control_silo_proxy_response |
33 | 36 |
|
34 | 37 |
|
@@ -1126,3 +1129,16 @@ def test_create_comment_attribution(self) -> None: |
1126 | 1129 | result = installation.create_comment_attribution(self.user.id, comment_text) |
1127 | 1130 |
|
1128 | 1131 | assert result == "**Test User** wrote:\n\n> This is a comment\n> With multiple lines" |
| 1132 | + |
| 1133 | + def test_get_repositories_unauthorized_raises_integration_configuration_error(self) -> None: |
| 1134 | + installation = self.installation |
| 1135 | + |
| 1136 | + with patch.object(installation, "get_client") as mock_get_client: |
| 1137 | + mock_get_client.return_value.search_projects.side_effect = ApiForbiddenError( |
| 1138 | + text=json.dumps({"message": "unauthorized"}) |
| 1139 | + ) |
| 1140 | + with pytest.raises(IntegrationConfigurationError) as exception_info: |
| 1141 | + installation.get_repositories() |
| 1142 | + assert ( |
| 1143 | + str(exception_info.value) == "Error Communicating with GitLab (HTTP 403): unauthorized" |
| 1144 | + ) |
0 commit comments