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 86d10da45c82b..691af75950039 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 @@ -397,6 +397,12 @@ def get_sample_connection_details(succeeded_at: str, failed_at: str) -> Mapping[ SAMPLE_SUCCESS_MESSAGE = {"code": "Success", "message": "Operation performed."} +def get_fivetran_connector_api_url(connector_id: str) -> str: + return ( + f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}" + ) + + @pytest.fixture(name="connector_id") def connector_id_fixture() -> str: return "connector_id" @@ -442,7 +448,7 @@ def fetch_workspace_data_api_mocks_fixture( response.add( method=responses.GET, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}/schemas", + url=f"{get_fivetran_connector_api_url(connector_id)}/schemas", json=SAMPLE_SCHEMA_CONFIG_FOR_CONNECTOR, status=200, ) @@ -461,7 +467,7 @@ def all_api_mocks_fixture( ) -> Iterator[responses.RequestsMock]: fetch_workspace_data_api_mocks.add( method=responses.GET, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}", + url=get_fivetran_connector_api_url(connector_id), json=get_sample_connection_details( succeeded_at=TEST_MAX_TIME_STR, failed_at=TEST_PREVIOUS_MAX_TIME_STR ), @@ -469,7 +475,7 @@ def all_api_mocks_fixture( ) fetch_workspace_data_api_mocks.add( method=responses.PATCH, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}", + url=get_fivetran_connector_api_url(connector_id), json=get_sample_connection_details( succeeded_at=TEST_MAX_TIME_STR, failed_at=TEST_PREVIOUS_MAX_TIME_STR ), @@ -477,19 +483,19 @@ def all_api_mocks_fixture( ) fetch_workspace_data_api_mocks.add( method=responses.POST, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}/force", + url=f"{get_fivetran_connector_api_url(connector_id)}/force", json=SAMPLE_SUCCESS_MESSAGE, status=200, ) fetch_workspace_data_api_mocks.add( method=responses.POST, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}/resync", + url=f"{get_fivetran_connector_api_url(connector_id)}/resync", json=SAMPLE_SUCCESS_MESSAGE, status=200, ) fetch_workspace_data_api_mocks.add( method=responses.POST, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}/schemas/tables/resync", + url=f"{get_fivetran_connector_api_url(connector_id)}/schemas/tables/resync", json=SAMPLE_SUCCESS_MESSAGE, status=200, ) 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 cabafb1d7db29..9513d814218d5 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 @@ -6,9 +6,6 @@ from dagster_fivetran.translator import MIN_TIME_STR from dagster_fivetran_tests.experimental.conftest import ( - FIVETRAN_API_BASE, - FIVETRAN_API_VERSION, - FIVETRAN_CONNECTOR_ENDPOINT, SAMPLE_SCHEMA_CONFIG_FOR_CONNECTOR, SAMPLE_SUCCESS_MESSAGE, TEST_ACCOUNT_ID, @@ -16,6 +13,7 @@ TEST_API_SECRET, TEST_MAX_TIME_STR, TEST_PREVIOUS_MAX_TIME_STR, + get_fivetran_connector_api_url, get_sample_connection_details, ) @@ -97,7 +95,7 @@ def test_basic_resource_request( # Replace the mock API call and set `failed_at` as more recent that `succeeded_at` all_api_mocks.replace( method_or_response=responses.GET, - url=f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}", + url=get_fivetran_connector_api_url(connector_id), json=get_sample_connection_details( succeeded_at=TEST_PREVIOUS_MAX_TIME_STR, failed_at=TEST_MAX_TIME_STR ), @@ -122,9 +120,7 @@ def test_sync_and_poll(n_polls, succeed_at_end, connector_id): ) client = resource.get_client() - test_connector_endpoint = ( - f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}" - ) + test_connector_api_url = get_fivetran_connector_api_url(connector_id) test_succeeded_at = TEST_MAX_TIME_STR test_failed_at = TEST_PREVIOUS_MAX_TIME_STR @@ -137,17 +133,17 @@ def _mock_interaction(): with responses.RequestsMock() as response: response.add( responses.GET, - f"{test_connector_endpoint}/schemas", + f"{test_connector_api_url}/schemas", json=SAMPLE_SCHEMA_CONFIG_FOR_CONNECTOR, ) - response.add(responses.PATCH, test_connector_endpoint, json=SAMPLE_SUCCESS_MESSAGE) + response.add(responses.PATCH, test_connector_api_url, json=SAMPLE_SUCCESS_MESSAGE) response.add( - responses.POST, f"{test_connector_endpoint}/force", json=SAMPLE_SUCCESS_MESSAGE + responses.POST, f"{test_connector_api_url}/force", json=SAMPLE_SUCCESS_MESSAGE ) # initial state response.add( responses.GET, - test_connector_endpoint, + test_connector_api_url, json=get_sample_connection_details( succeeded_at=MIN_TIME_STR, failed_at=MIN_TIME_STR ), @@ -156,7 +152,7 @@ def _mock_interaction(): for _ in range(n_polls): response.add( responses.GET, - test_connector_endpoint, + test_connector_api_url, json=get_sample_connection_details( succeeded_at=MIN_TIME_STR, failed_at=MIN_TIME_STR ), @@ -164,7 +160,7 @@ def _mock_interaction(): # final state will be updated response.add( responses.GET, - test_connector_endpoint, + test_connector_api_url, json=get_sample_connection_details( succeeded_at=test_succeeded_at, failed_at=test_failed_at ),