From b8f27289a65725adc82198cbda3bdd93794074d6 Mon Sep 17 00:00:00 2001 From: Jian Yuan Lee Date: Fri, 22 Sep 2023 10:17:49 +0100 Subject: [PATCH] Fix tests and typing --- src/sentry/integrations/bitbucket/client.py | 5 ++-- .../integrations/bitbucket/test_client.py | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/sentry/integrations/bitbucket/client.py b/src/sentry/integrations/bitbucket/client.py index bbe271f1ef720..80bf80136b1fd 100644 --- a/src/sentry/integrations/bitbucket/client.py +++ b/src/sentry/integrations/bitbucket/client.py @@ -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 @@ -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 @@ -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, diff --git a/tests/sentry/integrations/bitbucket/test_client.py b/tests/sentry/integrations/bitbucket/test_client.py index 57c90dfd9d0ab..df9c0b656c089 100644 --- a/tests/sentry/integrations/bitbucket/test_client.py +++ b/tests/sentry/integrations/bitbucket/test_client.py @@ -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" @@ -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): @@ -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