diff --git a/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/conftest.py b/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/conftest.py index e007f90f10795..f71bec7859a9f 100644 --- a/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/conftest.py +++ b/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/conftest.py @@ -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 diff --git a/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/test_resources.py b/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/test_resources.py index 8b198669e9173..a88e726933f8f 100644 --- a/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/test_resources.py +++ b/python_modules/libraries/dagster-fivetran/dagster_fivetran_tests/experimental/test_resources.py @@ -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