Skip to content

Commit

Permalink
Update api mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Nov 8, 2024
1 parent 34d9963 commit 7408fa2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ def group_id_fixture() -> str:


@pytest.fixture(
name="workspace_data_api_mocks",
name="fetch_workspace_data_api_mocks",
)
def workspace_data_api_mocks_fixture(
def fetch_workspace_data_api_mocks_fixture(
connector_id: str, destination_id: str, group_id: str
) -> Iterator[responses.RequestsMock]:
with responses.RequestsMock() as response:
Expand All @@ -424,18 +424,28 @@ def workspace_data_api_mocks_fixture(
status=200,
)

response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}/schemas",
json=SAMPLE_SCHEMA_CONFIG_FOR_CONNECTOR,
status=200,
)

response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}",
json=SAMPLE_CONNECTOR_DETAILS,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}/schemas",
json=SAMPLE_SCHEMA_CONFIG_FOR_CONNECTOR,
status=200,
)

yield response


@pytest.fixture(
name="all_api_mocks",
)
def all_api_mocks_fixture(
connector_id: str, destination_id: str, group_id: str, fetch_workspace_data_api_mocks: responses.RequestsMock
) -> responses.RequestsMock:
fetch_workspace_data_api_mocks.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}",
json=SAMPLE_CONNECTOR_DETAILS,
status=200,
)
yield fetch_workspace_data_api_mocks


Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import uuid
from typing import Callable

import responses
from dagster_fivetran import FivetranWorkspace


def test_fetch_fivetran_workspace_data(workspace_data_api_mocks_fn: Callable) -> None:
def test_fetch_fivetran_workspace_data(fetch_workspace_data_api_mocks: responses.RequestsMock) -> None:
api_key = uuid.uuid4().hex
api_secret = uuid.uuid4().hex

resource = FivetranWorkspace(api_key=api_key, api_secret=api_secret)

with workspace_data_api_mocks_fn(include_sync_endpoints=False):
actual_workspace_data = resource.fetch_fivetran_workspace_data()
assert len(actual_workspace_data.connectors_by_id) == 1
assert len(actual_workspace_data.destinations_by_id) == 1
actual_workspace_data = resource.fetch_fivetran_workspace_data()
assert len(actual_workspace_data.connectors_by_id) == 1
assert len(actual_workspace_data.destinations_by_id) == 1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_basic_resource_request(
connector_id: str,
destination_id: str,
group_id: str,
workspace_data_api_mocks: responses.RequestsMock,
all_api_mocks: responses.RequestsMock,
) -> None:
api_key = uuid.uuid4().hex
api_secret = uuid.uuid4().hex
Expand All @@ -22,11 +22,11 @@ def test_basic_resource_request(
client.get_groups()
client.get_schema_config_for_connector(connector_id=connector_id)

assert len(workspace_data_api_mocks.calls) == 5
assert len(all_api_mocks.calls) == 5

assert "Basic" in workspace_data_api_mocks.calls[0].request.headers["Authorization"]
assert connector_id in workspace_data_api_mocks.calls[0].request.url
assert group_id in workspace_data_api_mocks.calls[1].request.url
assert destination_id in workspace_data_api_mocks.calls[2].request.url
assert "groups" in workspace_data_api_mocks.calls[3].request.url
assert f"{connector_id}/schemas" in workspace_data_api_mocks.calls[4].request.url
assert "Basic" in all_api_mocks.calls[0].request.headers["Authorization"]
assert connector_id in all_api_mocks.calls[0].request.url
assert group_id in all_api_mocks.calls[1].request.url
assert destination_id in all_api_mocks.calls[2].request.url
assert "groups" in all_api_mocks.calls[3].request.url
assert f"{connector_id}/schemas" in all_api_mocks.calls[4].request.url

0 comments on commit 7408fa2

Please sign in to comment.