Skip to content

Commit

Permalink
Parametrize base url
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Dec 4, 2024
1 parent e04fef6 commit 6b52f15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ def _refresh_access_token(self) -> None:
self._make_request(
method="POST",
endpoint="/applications/token",
base_url=self.api_base_url,
data={
"client_id": self.client_id,
"client_secret": self.client_secret,
Expand All @@ -892,6 +893,7 @@ def _make_request(
self,
method: str,
endpoint: str,
base_url: str,
data: Optional[Mapping[str, Any]] = None,
include_additional_request_params: bool = True,
) -> Mapping[str, Any]:
Expand All @@ -900,14 +902,15 @@ def _make_request(
Args:
method (str): The http method to use for this request (e.g. "POST", "GET", "PATCH").
endpoint (str): The Airbyte API endpoint to send this request to.
base_url (str): The base url to the Airbyte API to use.
data (Optional[Dict[str, Any]]): JSON-formatted data string to be included in the request.
include_additional_request_params (bool): Whether to include authorization and user-agent headers
to the request parameters. Defaults to True.
Returns:
Dict[str, Any]: Parsed json data from the response to this request
"""
url = self.api_base_url + endpoint
url = base_url + endpoint
headers = {"accept": "application/json"}

num_retries = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:
with mock.patch("dagster_airbyte.resources.datetime", wraps=datetime) as dt:
# Test first call, must get the access token before calling the jobs api
dt.now.return_value = test_time_first_call
client._make_request(method="GET", endpoint="/test") # noqa
client._make_request(method="GET", endpoint="/test", base_url=client.api_base_url) # noqa

assert len(base_api_mocks.calls) == 2
access_token_call = base_api_mocks.calls[0]
Expand All @@ -43,7 +43,7 @@ def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:

# Test second call, occurs before the access token expiration, only the jobs api is called
dt.now.return_value = test_time_before_expiration
client._make_request(method="GET", endpoint="/test") # noqa
client._make_request(method="GET", endpoint="/test", base_url=client.api_base_url) # noqa

assert len(base_api_mocks.calls) == 1
jobs_api_call = base_api_mocks.calls[0]
Expand All @@ -55,7 +55,7 @@ def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:
# Test third call, occurs after the token expiration,
# must refresh the access token before calling the jobs api
dt.now.return_value = test_time_after_expiration
client._make_request(method="GET", endpoint="/test") # noqa
client._make_request(method="GET", endpoint="/test", base_url=client.api_base_url) # noqa

assert len(base_api_mocks.calls) == 2
access_token_call = base_api_mocks.calls[0]
Expand Down

0 comments on commit 6b52f15

Please sign in to comment.