|
9 | 9 |
|
10 | 10 | from fixtures.integrations.jira.stub_client import StubJiraApiClient |
11 | 11 | from fixtures.integrations.stub_service import StubService |
12 | | -from sentry.exceptions import InvalidConfiguration |
13 | 12 | from sentry.integrations.jira.integration import JiraIntegrationProvider |
14 | 13 | from sentry.integrations.jira.views import SALT |
| 14 | +from sentry.integrations.mixins.issues import IntegrationSyncTargetNotFound |
15 | 15 | from sentry.integrations.models.external_issue import ExternalIssue |
16 | 16 | from sentry.integrations.models.integration import Integration |
17 | 17 | from sentry.integrations.models.integration_external_project import IntegrationExternalProject |
18 | 18 | from sentry.integrations.models.organization_integration import OrganizationIntegration |
19 | 19 | from sentry.integrations.services.integration import integration_service |
20 | 20 | from sentry.models.grouplink import GroupLink |
21 | 21 | from sentry.models.groupmeta import GroupMeta |
22 | | -from sentry.shared_integrations.exceptions import IntegrationError |
| 22 | +from sentry.shared_integrations.exceptions import ( |
| 23 | + IntegrationError, |
| 24 | + IntegrationInstallationConfigurationError, |
| 25 | +) |
23 | 26 | from sentry.silo.base import SiloMode |
24 | 27 | from sentry.testutils.cases import APITestCase, IntegrationTestCase |
25 | 28 | from sentry.testutils.factories import EventType |
@@ -825,7 +828,7 @@ def test_sync_assignee_outbound_no_email(self): |
825 | 828 | "https://example.atlassian.net/rest/api/2/user/assignable/search", |
826 | 829 | json=[{"accountId": "deadbeef123", "displayName": "Dead Beef"}], |
827 | 830 | ) |
828 | | - with pytest.raises(InvalidConfiguration): |
| 831 | + with pytest.raises(IntegrationSyncTargetNotFound): |
829 | 832 | installation.sync_assignee_outbound(external_issue, user) |
830 | 833 |
|
831 | 834 | # No sync made as jira users don't have email addresses |
@@ -866,6 +869,56 @@ def test_sync_assignee_outbound_use_email_api(self): |
866 | 869 | assert assign_issue_response.status_code == 200 |
867 | 870 | assert assign_issue_response.request.body == b'{"accountId": "deadbeef123"}' |
868 | 871 |
|
| 872 | + @responses.activate |
| 873 | + def test_sync_assignee_outbound_api_unauthorized(self): |
| 874 | + user = serialize_rpc_user( self. create_user( email="[email protected]")) |
| 875 | + issue_id = "APP-123" |
| 876 | + installation = self.integration.get_installation(self.organization.id) |
| 877 | + assign_issue_url = "https://example.atlassian.net/rest/api/2/issue/%s/assignee" % issue_id |
| 878 | + |
| 879 | + external_issue = ExternalIssue.objects.create( |
| 880 | + organization_id=self.organization.id, integration_id=installation.model.id, key=issue_id |
| 881 | + ) |
| 882 | + |
| 883 | + responses.add( |
| 884 | + responses.GET, |
| 885 | + "https://example.atlassian.net/rest/api/2/user/assignable/search", |
| 886 | + json=[{ "accountId": "deadbeef123", "emailAddress": "[email protected]"}], |
| 887 | + ) |
| 888 | + |
| 889 | + responses.add(responses.PUT, assign_issue_url, status=401, json={}) |
| 890 | + |
| 891 | + with pytest.raises(IntegrationInstallationConfigurationError) as excinfo: |
| 892 | + installation.sync_assignee_outbound(external_issue, user) |
| 893 | + |
| 894 | + assert str(excinfo.value) == "Insufficient permissions to assign user to the Jira issue." |
| 895 | + assert len(responses.calls) == 2 |
| 896 | + |
| 897 | + @responses.activate |
| 898 | + def test_sync_assignee_outbound_api_error(self): |
| 899 | + user = serialize_rpc_user( self. create_user( email="[email protected]")) |
| 900 | + issue_id = "APP-123" |
| 901 | + installation = self.integration.get_installation(self.organization.id) |
| 902 | + assign_issue_url = "https://example.atlassian.net/rest/api/2/issue/%s/assignee" % issue_id |
| 903 | + |
| 904 | + external_issue = ExternalIssue.objects.create( |
| 905 | + organization_id=self.organization.id, integration_id=installation.model.id, key=issue_id |
| 906 | + ) |
| 907 | + |
| 908 | + responses.add( |
| 909 | + responses.GET, |
| 910 | + "https://example.atlassian.net/rest/api/2/user/assignable/search", |
| 911 | + json=[{ "accountId": "deadbeef123", "emailAddress": "[email protected]"}], |
| 912 | + ) |
| 913 | + |
| 914 | + responses.add(responses.PUT, assign_issue_url, status=400, json={}) |
| 915 | + |
| 916 | + with pytest.raises(IntegrationError) as excinfo: |
| 917 | + installation.sync_assignee_outbound(external_issue, user) |
| 918 | + |
| 919 | + assert str(excinfo.value) == "There was an error assigning the issue." |
| 920 | + assert len(responses.calls) == 2 |
| 921 | + |
869 | 922 |
|
870 | 923 | @control_silo_test |
871 | 924 | class JiraIntegrationTest(APITestCase): |
|
0 commit comments