コード例 #1
0
    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
コード例 #2
0
ファイル: test_utils.py プロジェクト: pasala91/test
 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)",
     )
コード例 #3
0
    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",
                    },
                },
            )
コード例 #4
0
 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
コード例 #5
0
 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)
コード例 #6
0
 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
コード例 #7
0
    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
コード例 #8
0
    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
コード例 #9
0
    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
            )
コード例 #10
0
 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",
                 },
             },
         )
コード例 #11
0
    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
コード例 #12
0
ファイル: test_utils.py プロジェクト: pasala91/test
 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
コード例 #13
0
ファイル: test_utils.py プロジェクト: pasala91/test
 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",
     )