Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Nov 21, 2024
1 parent 3c25a4c commit 66bd6ae
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,21 @@ def test_basic_resource_request(


@pytest.mark.parametrize(
"n_polls, succeed_at_end",
[(0, True), (0, False), (4, True), (4, False), (30, True)],
"method, n_polls, succeed_at_end",
[
("sync_and_poll", 0, True),
("sync_and_poll", 0, False),
("sync_and_poll", 4, True),
("sync_and_poll", 4, False),
("sync_and_poll", 30, True),
("resync_and_poll", 0, True),
("resync_and_poll", 0, False),
("resync_and_poll", 4, True),
("resync_and_poll", 4, False),
("resync_and_poll", 30, True),
],
)
def test_sync_and_poll(n_polls, succeed_at_end, connector_id):
def test_sync_and_poll_methods(method, n_polls, succeed_at_end, connector_id):
resource = FivetranWorkspace(
account_id=TEST_ACCOUNT_ID, api_key=TEST_API_KEY, api_secret=TEST_API_SECRET
)
Expand All @@ -127,6 +138,11 @@ def test_sync_and_poll(n_polls, succeed_at_end, connector_id):
test_connector_endpoint = (
f"{FIVETRAN_API_BASE}/{FIVETRAN_API_VERSION}/{FIVETRAN_CONNECTOR_ENDPOINT}/{connector_id}"
)
test_sync_endpoint = (
f"{test_connector_endpoint}/force"
if method == "sync_and_poll"
else f"{test_connector_endpoint}/resync"
)

test_succeeded_at = TEST_MAX_TIME_STR
test_failed_at = TEST_PREVIOUS_MAX_TIME_STR
Expand All @@ -143,9 +159,7 @@ def _mock_interaction():
json=SAMPLE_SCHEMA_CONFIG_FOR_CONNECTOR,
)
response.add(responses.PATCH, test_connector_endpoint, json=SAMPLE_SUCCESS_MESSAGE)
response.add(
responses.POST, f"{test_connector_endpoint}/force", json=SAMPLE_SUCCESS_MESSAGE
)
response.add(responses.POST, test_sync_endpoint, json=SAMPLE_SUCCESS_MESSAGE)
# initial state
response.add(
responses.GET,
Expand All @@ -171,7 +185,8 @@ def _mock_interaction():
succeeded_at=test_succeeded_at, failed_at=test_failed_at
),
)
return client.sync_and_poll(connector_id, poll_interval=0.1)
test_method = getattr(client, method)
return test_method(connector_id, poll_interval=0.1)

if succeed_at_end:
assert _mock_interaction() == FivetranOutput(
Expand Down

0 comments on commit 66bd6ae

Please sign in to comment.