def test_assign_use_email_api(self, mock_sync_group_assignee_inbound):
        org = self.organization

        integration = Integration.objects.create(
            provider="jira",
            name="Example Jira",
            metadata={
                "oauth_client_id": "oauth-client-id",
                "shared_secret": "a-super-secret-key-from-atlassian",
                "base_url": "https://example.atlassian.net",
                "domain_name": "example.atlassian.net",
            },
        )
        integration.add_organization(org, self.user)

        path = reverse("sentry-extensions-jira-issue-updated")

        responses.add(
            responses.GET,
            "https://example.atlassian.net/rest/api/3/user/email",
            json={"accountId": "deadbeef123", "email": self.user.email},
            match_querystring=False,
        )

        with patch(
            "sentry.integrations.jira.webhooks.get_integration_from_jwt", return_value=integration
        ):
            data = StubService.get_stub_data("jira", "edit_issue_assignee_payload.json")
            data["issue"]["fields"]["assignee"]["emailAddress"] = ""
            resp = self.client.post(path, data=data, HTTP_AUTHORIZATION="JWT anexampletoken")
            assert resp.status_code == 200
            assert mock_sync_group_assignee_inbound.called
            assert len(responses.calls) == 1
Exemple #2
0
 def test_jira_server(self):
     user_response = StubService.get_stub_data("jira",
                                               "jira_server_user.json")
     assert build_user_choice(user_response, user_id_field="name") == (
         "bob",
         "Bobby - [email protected] (bob)",
     )
    def test_simple_status_sync_inbound(self, mock_sync_status_inbound):
        org = self.organization

        integration = Integration.objects.create(provider="jira", name="Example Jira")
        integration.add_organization(org, self.user)

        path = reverse("sentry-extensions-jira-issue-updated")

        with patch(
            "sentry.integrations.jira.webhooks.get_integration_from_jwt", return_value=integration
        ) as mock_get_integration_from_jwt:
            data = StubService.get_stub_data("jira", "edit_issue_status_payload.json")
            resp = self.client.post(path, data=data, HTTP_AUTHORIZATION="JWT anexampletoken")
            assert resp.status_code == 200
            mock_get_integration_from_jwt.assert_called_with(
                "anexampletoken", "/extensions/jira/issue-updated/", "jira", {}, method="POST"
            )
            mock_sync_status_inbound.assert_called_with(
                "APP-123",
                {
                    "changelog": {
                        "from": "10101",
                        "field": "status",
                        "fromString": "Done",
                        "to": "3",
                        "toString": "In Progress",
                        "fieldtype": "jira",
                        "fieldId": "status",
                    },
                    "issue": {
                        "fields": {"project": {"id": "10000", "key": "APP"}},
                        "key": "APP-123",
                    },
                },
            )
 def test_missing_changelog(self):
     with patch(
             "sentry.integrations.jira.webhooks.get_integration_from_jwt",
             return_value=self.integration,
     ):
         data = StubService.get_stub_data("jira", "changelog_missing.json")
         resp = self.client.post(self.path,
                                 data=data,
                                 HTTP_AUTHORIZATION="JWT anexampletoken")
         assert resp.status_code == 200
 def test_simple_deassign(self, mock_sync_group_assignee_inbound):
     with patch(
             "sentry.integrations.jira.webhooks.get_integration_from_jwt",
             return_value=self.integration,
     ):
         data = StubService.get_stub_data(
             "jira", "edit_issue_no_assignee_payload.json")
         resp = self.client.post(self.path,
                                 data=data,
                                 HTTP_AUTHORIZATION="JWT anexampletoken")
         assert resp.status_code == 200
         mock_sync_group_assignee_inbound.assert_called_with(
             self.integration, None, "APP-123", assign=False)
 def test_assign_missing_email(self, mock_sync_group_assignee_inbound):
     with patch(
             "sentry.integrations.jira.webhooks.get_integration_from_jwt",
             return_value=self.integration,
     ):
         data = StubService.get_stub_data(
             "jira", "edit_issue_assignee_payload.json")
         data["issue"]["fields"]["assignee"]["emailAddress"] = ""
         resp = self.client.post(self.path,
                                 data=data,
                                 HTTP_AUTHORIZATION="JWT anexampletoken")
         assert resp.status_code == 200
         assert not mock_sync_group_assignee_inbound.called
    def test_missing_changelog(self):
        org = self.organization

        integration = Integration.objects.create(provider="jira", name="Example Jira")
        integration.add_organization(org, self.user)

        path = reverse("sentry-extensions-jira-issue-updated")

        with patch(
            "sentry.integrations.jira.webhooks.get_integration_from_jwt", return_value=integration
        ):
            data = StubService.get_stub_data("jira", "changelog_missing.json")
            resp = self.client.post(path, data=data, HTTP_AUTHORIZATION="JWT anexampletoken")
            assert resp.status_code == 200
    def test_assign_missing_email(self, mock_sync_group_assignee_inbound):
        org = self.organization

        integration = Integration.objects.create(provider="jira", name="Example Jira")
        integration.add_organization(org, self.user)

        path = reverse("sentry-extensions-jira-issue-updated")

        with patch(
            "sentry.integrations.jira.webhooks.get_integration_from_jwt", return_value=integration
        ):
            data = StubService.get_stub_data("jira", "edit_issue_assignee_payload.json")
            data["issue"]["fields"]["assignee"]["emailAddress"] = ""
            resp = self.client.post(path, data=data, HTTP_AUTHORIZATION="JWT anexampletoken")
            assert resp.status_code == 200
            assert not mock_sync_group_assignee_inbound.called
    def test_simple_deassign(self, mock_sync_group_assignee_inbound):
        org = self.organization

        integration = Integration.objects.create(provider="jira", name="Example Jira")
        integration.add_organization(org, self.user)

        path = reverse("sentry-extensions-jira-issue-updated")

        with patch(
            "sentry.integrations.jira.webhooks.get_integration_from_jwt", return_value=integration
        ):
            data = StubService.get_stub_data("jira", "edit_issue_no_assignee_payload.json")
            resp = self.client.post(path, data=data, HTTP_AUTHORIZATION="JWT anexampletoken")
            assert resp.status_code == 200
            mock_sync_group_assignee_inbound.assert_called_with(
                integration, None, "APP-123", assign=False
            )
 def test_simple_status_sync_inbound(self, mock_sync_status_inbound):
     with patch(
             "sentry.integrations.jira.webhooks.get_integration_from_jwt",
             return_value=self.integration,
     ) as mock_get_integration_from_jwt:
         data = StubService.get_stub_data("jira",
                                          "edit_issue_status_payload.json")
         resp = self.client.post(self.path,
                                 data=data,
                                 HTTP_AUTHORIZATION="JWT anexampletoken")
         assert resp.status_code == 200
         mock_get_integration_from_jwt.assert_called_with(
             "anexampletoken",
             "/extensions/jira/issue-updated/",
             "jira", {},
             method="POST")
         mock_sync_status_inbound.assert_called_with(
             "APP-123",
             {
                 "changelog": {
                     "from": "10101",
                     "field": "status",
                     "fromString": "Done",
                     "to": "3",
                     "toString": "In Progress",
                     "fieldtype": "jira",
                     "fieldId": "status",
                 },
                 "issue": {
                     "fields": {
                         "project": {
                             "id": "10000",
                             "key": "APP"
                         }
                     },
                     "key": "APP-123",
                 },
             },
         )
    def test_assign_use_email_api(self, mock_sync_group_assignee_inbound):
        responses.add(
            responses.GET,
            "https://example.atlassian.net/rest/api/3/user/email",
            json={
                "accountId": "deadbeef123",
                "email": self.user.email
            },
            match_querystring=False,
        )

        with patch(
                "sentry.integrations.jira.webhooks.get_integration_from_jwt",
                return_value=self.integration,
        ):
            data = StubService.get_stub_data(
                "jira", "edit_issue_assignee_payload.json")
            data["issue"]["fields"]["assignee"]["emailAddress"] = ""
            resp = self.client.post(self.path,
                                    data=data,
                                    HTTP_AUTHORIZATION="JWT anexampletoken")
            assert resp.status_code == 200
            assert mock_sync_group_assignee_inbound.called
            assert len(responses.calls) == 1
Exemple #12
0
 def test_unexpected_id(self):
     user_response = StubService.get_stub_data("jira", "user.json")
     assert build_user_choice(user_response, user_id_field="name") is None
Exemple #13
0
 def test_jira_cloud(self):
     user_response = StubService.get_stub_data("jira", "user.json")
     assert build_user_choice(user_response, user_id_field="accountId") == (
         "012345:00000000-1111-2222-3333-444444444444",
         "Saif Hakim",
     )