Skip to content

Commit

Permalink
Fix tests and typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyuan committed Sep 24, 2023
1 parent 0c7236c commit b8f2728
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/sentry/integrations/bitbucket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime
import logging
from typing import Any, Optional
from typing import Any
from urllib.parse import parse_qs, urlparse, urlsplit

from requests import PreparedRequest
Expand All @@ -11,6 +11,7 @@
from sentry.models import Repository
from sentry.services.hybrid_cloud.integration.model import RpcIntegration
from sentry.services.hybrid_cloud.util import control_silo_function
from sentry.shared_integrations.client.base import BaseApiResponseX
from sentry.shared_integrations.client.proxy import IntegrationProxyClient, infer_org_integration
from sentry.utils import jwt
from sentry.utils.http import absolute_uri
Expand Down Expand Up @@ -176,7 +177,7 @@ def compare_commits(self, repo, start_sha, end_sha):

return self.zip_commit_data(repo, commits)

def check_file(self, repo: Repository, path: str, version: str) -> Optional[str]:
def check_file(self, repo: Repository, path: str, version: str) -> BaseApiResponseX:
return self.head_cached(
path=BitbucketAPIPath.source.format(
repo=repo.name,
Expand Down
24 changes: 15 additions & 9 deletions tests/sentry/integrations/bitbucket/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
from requests import Request

from sentry.integrations.bitbucket.client import BitbucketApiClient, BitbucketAPIPath
from sentry.integrations.bitbucket.integration import BitbucketIntegration
from sentry.integrations.utils.atlassian_connect import get_query_hash
from sentry.models import Repository
from sentry.shared_integrations.exceptions import ApiError
from sentry.shared_integrations.response.base import BaseApiResponse
from sentry.silo.base import SiloMode
from sentry.silo.util import PROXY_BASE_PATH, PROXY_OI_HEADER, PROXY_SIGNATURE_HEADER
from sentry.testutils.cases import BaseTestCase, TestCase
from sentry.testutils.helpers.datetime import freeze_time
from sentry.testutils.silo import control_silo_test
from sentry.testutils.silo import assume_test_silo_mode, control_silo_test

control_address = "http://controlserver"
secret = "hush-hush-im-invisible"
Expand Down Expand Up @@ -43,16 +45,19 @@ def setUp(self):
"type": "team",
},
)
self.install = self.integration.get_installation(self.organization.id)
install = self.integration.get_installation(self.organization.id)
assert isinstance(install, BitbucketIntegration)
self.install = install
self.bitbucket_client: BitbucketApiClient = self.install.get_client()

self.repo = Repository.objects.create(
provider="bitbucket",
name="sentryuser/newsdiffs",
organization_id=self.organization.id,
config={"name": "sentryuser/newsdiffs"},
integration_id=self.integration.id,
)
with assume_test_silo_mode(SiloMode.REGION):
self.repo = Repository.objects.create(
provider="bitbucket",
name="sentryuser/newsdiffs",
organization_id=self.organization.id,
config={"name": "sentryuser/newsdiffs"},
integration_id=self.integration.id,
)

@freeze_time("2023-01-01 01:01:01")
def test_authorize_request(self):
Expand Down Expand Up @@ -93,6 +98,7 @@ def test_check_file(self):
)

resp = self.bitbucket_client.check_file(self.repo, path, version)
assert isinstance(resp, BaseApiResponse)
assert resp.status_code == 200

@responses.activate
Expand Down

0 comments on commit b8f2728

Please sign in to comment.