Skip to content

Commit

Permalink
Update request mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Nov 8, 2024
1 parent e4892e8 commit f4fa792
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,42 +227,38 @@ def group_id_fixture() -> str:


@pytest.fixture(
name="workspace_data_api_mocks_fn",
name="workspace_data_api_mocks",
)
def workspace_data_api_mocks_fn_fixture(
def workspace_data_api_mocks_fixture(
connector_id: str, destination_id: str, group_id: str
) -> Callable:
@contextlib.contextmanager
def _method() -> Iterator[responses.RequestsMock]:
with responses.RequestsMock() as response:
response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/groups",
json=SAMPLE_GROUPS,
status=200,
)
) -> Iterator[responses.RequestsMock]:
with responses.RequestsMock() as response:
response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/groups",
json=SAMPLE_GROUPS,
status=200,
)

response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/groups/{group_id}/connectors",
json=SAMPLE_CONNECTORS_FOR_GROUP,
status=200,
)
response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/groups/{group_id}/connectors",
json=SAMPLE_CONNECTORS_FOR_GROUP,
status=200,
)

response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/destinations/{destination_id}",
json=SAMPLE_DESTINATION_DETAILS,
status=200,
)
response.add(
method=responses.GET,
url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/destinations/{destination_id}",
json=SAMPLE_DESTINATION_DETAILS,
status=200,
)

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

yield response

return _method
yield response
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import uuid
from typing import Callable
import responses

from dagster_fivetran import FivetranWorkspace


def test_basic_resource_request(
connector_id: str, destination_id: str, group_id: str, workspace_data_api_mocks_fn: Callable
connector_id: str, destination_id: str, group_id: str, 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() as response:
client = resource.get_client()
client.get_connector_details(connector_id=connector_id)
client.get_connectors_for_group(group_id=group_id)
client.get_destination_details(destination_id=destination_id)
client.get_groups()
client = resource.get_client()
client.get_connector_details(connector_id=connector_id)
client.get_connectors_for_group(group_id=group_id)
client.get_destination_details(destination_id=destination_id)
client.get_groups()

assert len(response.calls) == 4
assert len(workspace_data_api_mocks.calls) == 4

assert "Basic" in response.calls[0].request.headers["Authorization"]
assert connector_id in response.calls[0].request.url
assert group_id in response.calls[1].request.url
assert destination_id in response.calls[2].request.url
assert "groups" in response.calls[3].request.url
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

0 comments on commit f4fa792

Please sign in to comment.