Exemple #1
0
    def test_creates_issue(self):
        event = self.get_event()
        jira_rule = self.get_rule(
            data={
                "issuetype": "1",
                "labels": "bunnies",
                "customfield_10200": "sad",
                "customfield_10300": ["Feature 1", "Feature 2"],
                "project": "10000",
                "jira_integration": self.integration.id,
                "jira_project": "10000",
                "issue_type": "Bug",
                "fixVersions": "[10000]",
            })
        jira_rule.rule = Rule.objects.create(
            project=self.project,
            label="test rule",
        )

        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,
        )

        jira_rule.data["key"] = "APP-123"
        responses.add(
            method=responses.POST,
            url="https://example.atlassian.net/rest/api/2/issue",
            json=jira_rule.data,
            status=202,
            content_type="application/json",
        )
        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,
        )

        results = list(jira_rule.after(event=event, state=self.get_state()))
        assert len(results) == 1

        # Trigger rule callback
        results[0].callback(event, futures=[])

        # Make assertions about what would be sent.
        data = json.loads(responses.calls[2].request.body)
        assert data["fields"]["summary"] == event.title
        assert event.message in data["fields"]["description"]
        assert data["fields"]["issuetype"]["id"] == "1"

        external_issue = ExternalIssue.objects.get(key="APP-123")
        assert external_issue
 def responder(request):
     query = parse_qs(urlparse(request.url).query)
     assert "HSP" == query["project"][0]
     assert "bob" == query["query"][0]
     data = StubService.get_stub_json("jira",
                                      "user_search_response.json")
     return 200, {}, data
Exemple #3
0
    def test_issue_search_text(self):
        responses.add(
            responses.GET,
            "https://example.atlassian.net/rest/api/2/search/",
            body=StubService.get_stub_json("jira", "search_response.json"),
            content_type="json",
            match_querystring=False,
        )
        org = self.organization
        self.login_as(self.user)

        path = reverse("sentry-extensions-jira-search", args=[org.slug, self.integration.id])

        resp = self.client.get("%s?field=externalIssue&query=test" % (path,))
        assert resp.status_code == 200
        assert resp.data == [{"label": "(HSP-1) this is a test issue summary", "value": "HSP-1"}]
Exemple #4
0
 def responder(request):
     query = parse_qs(urlparse(request.url).query)
     assert 'id="hsp-1"' == query["jql"][0]
     data = StubService.get_stub_json("jira", "search_response.json")
     return 200, {}, data