Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Dec 5, 2024
1 parent e249d8e commit d89aee3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
import responses
from dagster_airbyte.resources import AIRBYTE_API_BASE, AIRBYTE_API_VERSION

TEST_WORKSPACE_ID = "some_workspace_id"
TEST_CLIENT_ID = "some_client_id"
TEST_CLIENT_SECRET = "some_client_secret"

TEST_ACCESS_TOKEN = "some_access_token"

# Taken from Airbyte API documentation
# https://reference.airbyte.com/reference/createaccesstoken
SAMPLE_ACCESS_TOKEN = {"access_token": "some_access_token"}
SAMPLE_ACCESS_TOKEN = {"access_token": TEST_ACCESS_TOKEN}


@pytest.fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
import responses
from dagster_airbyte import AirbyteCloudWorkspace

from dagster_airbyte_tests.experimental.conftest import (
TEST_ACCESS_TOKEN,
TEST_CLIENT_ID,
TEST_CLIENT_SECRET,
TEST_WORKSPACE_ID,
)


def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:
resource = AirbyteCloudWorkspace(
workspace_id="some_workspace_id",
client_id="some_client_id",
client_secret="some_client_secret",
workspace_id=TEST_WORKSPACE_ID,
client_id=TEST_CLIENT_ID,
client_secret=TEST_CLIENT_SECRET,
)
client = resource.get_client()

Expand All @@ -35,9 +42,9 @@ def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:

assert "Authorization" not in access_token_call.request.headers
access_token_call_body = json.loads(access_token_call.request.body.decode("utf-8"))
assert access_token_call_body["client_id"] == "some_client_id"
assert access_token_call_body["client_secret"] == "some_client_secret"
assert jobs_api_call.request.headers["Authorization"] == "Bearer some_access_token"
assert access_token_call_body["client_id"] == TEST_CLIENT_ID
assert access_token_call_body["client_secret"] == TEST_CLIENT_SECRET
assert jobs_api_call.request.headers["Authorization"] == f"Bearer {TEST_ACCESS_TOKEN}"

base_api_mocks.calls.reset()

Expand All @@ -48,7 +55,7 @@ def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:
assert len(base_api_mocks.calls) == 1
jobs_api_call = base_api_mocks.calls[0]

assert jobs_api_call.request.headers["Authorization"] == "Bearer some_access_token"
assert jobs_api_call.request.headers["Authorization"] == f"Bearer {TEST_ACCESS_TOKEN}"

base_api_mocks.calls.reset()

Expand All @@ -63,6 +70,6 @@ def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None:

assert "Authorization" not in access_token_call.request.headers
access_token_call_body = json.loads(access_token_call.request.body.decode("utf-8"))
assert access_token_call_body["client_id"] == "some_client_id"
assert access_token_call_body["client_secret"] == "some_client_secret"
assert jobs_api_call.request.headers["Authorization"] == "Bearer some_access_token"
assert access_token_call_body["client_id"] == TEST_CLIENT_ID
assert access_token_call_body["client_secret"] == TEST_CLIENT_SECRET
assert jobs_api_call.request.headers["Authorization"] == f"Bearer {TEST_ACCESS_TOKEN}"

0 comments on commit d89aee3

Please sign in to comment.