Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Nov 25, 2024
1 parent 4178aa2 commit 0f5c606
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
Expand All @@ -461,35 +467,35 @@ 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
),
status=200,
)
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
),
status=200,
)
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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
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,
TEST_API_KEY,
TEST_API_SECRET,
TEST_MAX_TIME_STR,
TEST_PREVIOUS_MAX_TIME_STR,
get_fivetran_connector_api_url,
get_sample_connection_details,
)

Expand Down Expand Up @@ -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
),
Expand All @@ -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
Expand All @@ -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
),
Expand All @@ -156,15 +152,15 @@ 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
),
)
# 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
),
Expand Down

0 comments on commit 0f5c606

Please sign in to comment.