def test_create_issue_labels_and_option(self):
        installation = self.integration.get_installation(self.organization.id)

        responses.add(
            responses.GET,
            "https://example.atlassian.net/rest/api/2/issue/createmeta",
            body=StubService.get_stub_json("jira", "createmeta_response.json"),
            content_type="json",
            match_querystring=False,
        )
        responses.add(
            responses.GET,
            "https://example.atlassian.net/rest/api/2/issue/APP-123",
            body=StubService.get_stub_json("jira", "get_issue_response.json"),
            content_type="json",
            match_querystring=False,
        )

        def responder(request):
            body = json.loads(request.body)
            assert body["fields"]["labels"] == ["fuzzy", "bunnies"]
            assert body["fields"]["customfield_10200"] == {"value": "sad"}
            assert body["fields"]["customfield_10300"] == [
                {
                    "value": "Feature 1"
                },
                {
                    "value": "Feature 2"
                },
            ]
            return (200, {
                "content-type": "application/json"
            }, '{"key":"APP-123"}')

        responses.add_callback(
            responses.POST,
            "https://example.atlassian.net/rest/api/2/issue",
            callback=responder,
            match_querystring=False,
        )

        result = installation.create_issue({
            "title":
            "example summary",
            "description":
            "example bug report",
            "issuetype":
            "1",
            "project":
            "10000",
            "customfield_10200":
            "sad",
            "customfield_10300": ["Feature 1", "Feature 2"],
            "labels":
            "fuzzy , ,  bunnies",
        })
        assert result["key"] == "APP-123"
Пример #2
0
    def test_get_create_issue_config_with_persisted_reporter(self):
        event = self.store_event(
            data={
                "event_id": "a" * 32,
                "message": "message",
                "timestamp": self.min_ago,
                "stacktrace": copy.deepcopy(DEFAULT_EVENT_DATA["stacktrace"]),
            },
            project_id=self.project.id,
        )
        group = event.group
        installation = self.integration.get_installation(self.organization.id)

        # When persisted reporter matches a user JIRA knows about, a default is picked.
        account_id = StubService.get_stub_data("jira", "user.json")["accountId"]
        installation.store_issue_last_defaults(self.project, self.user, {"reporter": account_id})
        with mock.patch.object(installation, "get_client", get_client):
            create_issue_config = installation.get_create_issue_config(group, self.user)
        reporter_field = [field for field in create_issue_config if field["name"] == "reporter"][0]
        assert reporter_field == {
            "name": "reporter",
            "url": reverse(
                "sentry-extensions-jira-search", args=[self.organization.slug, self.integration.id]
            ),
            "required": True,
            "choices": [("012345:00000000-1111-2222-3333-444444444444", "Saif Hakim")],
            "default": "012345:00000000-1111-2222-3333-444444444444",
            "label": "Reporter",
            "type": "select",
        }

        # When persisted reporter does not match a user JIRA knows about, field is left blank.
        installation.store_issue_last_defaults(
            self.project, self.user, {"reporter": "invalid-reporter-id"}
        )

        with mock.patch.object(installation, "get_client", get_client):
            create_issue_config = installation.get_create_issue_config(group, self.user)
        reporter_field = [field for field in create_issue_config if field["name"] == "reporter"][0]
        assert reporter_field == {
            "name": "reporter",
            "url": reverse(
                "sentry-extensions-jira-search", args=[self.organization.slug, self.integration.id]
            ),
            "required": True,
            "choices": [],
            "label": "Reporter",
            "type": "select",
        }