Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/apify/_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __post_init__(self) -> None:


def to_client_representations(webhooks: list[Webhook] | None) -> list[WebhookRepresentation] | None:
"""Project SDK webhooks to the minimal ad-hoc representation accepted by the client's `start()` / `call()`."""
"""Convert SDK webhooks to the ad-hoc representation accepted by the client's `start()` / `call()`."""
if not webhooks:
return None
return [
Expand All @@ -57,6 +57,9 @@ def to_client_representations(webhooks: list[Webhook] | None) -> list[WebhookRep
request_url=w.request_url,
payload_template=w.payload_template,
headers_template=w.headers_template,
idempotency_key=w.idempotency_key,
ignore_ssl_errors=w.ignore_ssl_errors,
do_not_retry=w.do_not_retry,
)
for w in webhooks
]
44 changes: 44 additions & 0 deletions tests/unit/actor/test_actor_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,50 @@ async def test_remote_method_with_webhooks(
assert kwargs['webhooks'] is not None


@pytest.mark.parametrize(('client_resource', 'client_method', 'actor_method_name', 'entity_id'), _ACTOR_REMOTE_METHODS)
async def test_remote_method_forwards_all_webhook_fields(
apify_client_async_patcher: ApifyClientAsyncPatcher,
fake_actor_run: Run,
client_resource: str,
client_method: str,
actor_method_name: str,
entity_id: str,
) -> None:
"""Test that start/call/call_task forward all `Webhook` fields to the client representation."""
apify_client_async_patcher.patch(client_resource, client_method, return_value=fake_actor_run)

async with Actor:
actor_method = getattr(Actor, actor_method_name)
await actor_method(
entity_id,
webhooks=[
Webhook(
event_types=['ACTOR.RUN.SUCCEEDED'],
request_url='https://example.com',
payload_template='{"hello": "world"}',
headers_template='{"Authorization": "Bearer ..."}',
idempotency_key='some-key',
ignore_ssl_errors=True,
do_not_retry=True,
)
],
)

calls = apify_client_async_patcher.calls[client_resource][client_method]
assert len(calls) == 1
_, kwargs = calls[0][0], calls[0][1]
(representation,) = kwargs['webhooks']
assert representation.model_dump(by_alias=True, exclude_none=True) == {
'eventTypes': ['ACTOR.RUN.SUCCEEDED'],
'requestUrl': 'https://example.com',
'payloadTemplate': '{"hello": "world"}',
'headersTemplate': '{"Authorization": "Bearer ..."}',
'idempotencyKey': 'some-key',
'ignoreSslErrors': True,
'doNotRetry': True,
}


@pytest.mark.parametrize(('client_resource', 'client_method', 'actor_method_name', 'entity_id'), _ACTOR_REMOTE_METHODS)
async def test_remote_method_with_timedelta_timeout(
apify_client_async_patcher: ApifyClientAsyncPatcher,
Expand Down
Loading