mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
import responses
|
|
from django.urls import reverse
|
|
|
|
from sentry.testutils.cases import APITestCase
|
|
from sentry.testutils.silo import control_silo_test
|
|
|
|
|
|
@control_silo_test
|
|
class BitbucketSearchEndpointTest(APITestCase):
|
|
def setUp(self):
|
|
self.base_url = "https://api.bitbucket.org"
|
|
self.shared_secret = "234567890"
|
|
self.subject = "connect:1234567"
|
|
self.integration, _ = self.create_provider_integration_for(
|
|
self.organization,
|
|
self.user,
|
|
provider="bitbucket",
|
|
external_id=self.subject,
|
|
name="meredithanya",
|
|
metadata={
|
|
"base_url": self.base_url,
|
|
"shared_secret": self.shared_secret,
|
|
"subject": self.subject,
|
|
},
|
|
)
|
|
|
|
self.login_as(self.user)
|
|
self.path = reverse(
|
|
"sentry-extensions-bitbucket-search", args=[self.organization.slug, self.integration.id]
|
|
)
|
|
|
|
@responses.activate
|
|
def test_search_issues(self):
|
|
responses.add(
|
|
responses.GET,
|
|
"https://api.bitbucket.org/2.0/repositories/meredithanya/apples/issues",
|
|
json={
|
|
"values": [
|
|
{"id": "123", "title": "Issue Title 123"},
|
|
{"id": "456", "title": "Issue Title 456"},
|
|
]
|
|
},
|
|
)
|
|
resp = self.client.get(
|
|
self.path,
|
|
data={"field": "externalIssue", "query": "issue", "repo": "meredithanya/apples"},
|
|
)
|
|
|
|
assert resp.status_code == 200
|
|
assert resp.data == [
|
|
{"label": "#123 Issue Title 123", "value": "123"},
|
|
{"label": "#456 Issue Title 456", "value": "456"},
|
|
]
|
|
|
|
@responses.activate
|
|
def test_search_repositories(self):
|
|
responses.add(
|
|
responses.GET,
|
|
"https://api.bitbucket.org/2.0/repositories/meredithanya",
|
|
json={"values": [{"full_name": "meredithanya/apples"}]},
|
|
)
|
|
resp = self.client.get(self.path, data={"field": "repo", "query": "apple"})
|
|
|
|
assert resp.status_code == 200
|
|
assert resp.data == [{"label": "meredithanya/apples", "value": "meredithanya/apples"}]
|
|
|
|
@responses.activate
|
|
def test_search_repositories_no_issue_tracker(self):
|
|
responses.add(
|
|
responses.GET,
|
|
"https://api.bitbucket.org/2.0/repositories/meredithanya/apples/issues",
|
|
json={"type": "error", "error": {"message": "Repository has no issue tracker."}},
|
|
status=404,
|
|
)
|
|
resp = self.client.get(
|
|
self.path,
|
|
data={"field": "externalIssue", "query": "issue", "repo": "meredithanya/apples"},
|
|
)
|
|
assert resp.status_code == 400
|
|
assert resp.data == {"detail": "Bitbucket Repository has no issue tracker."}
|