|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import io |
| 4 | +import json |
| 5 | +from base64 import b64decode |
4 | 6 | from datetime import timedelta |
5 | 7 | from http import HTTPStatus |
6 | 8 | from typing import TYPE_CHECKING |
|
27 | 29 |
|
28 | 30 | if TYPE_CHECKING: |
29 | 31 | from apify_client._typeddicts import WebhookRepresentationDict |
| 32 | + from apify_client.types import WebhooksList |
30 | 33 |
|
31 | 34 |
|
32 | 35 | def test_to_safe_id() -> None: |
@@ -58,6 +61,64 @@ def test_encode_webhooks_to_base64() -> None: |
58 | 61 | ) |
59 | 62 |
|
60 | 63 |
|
| 64 | +@pytest.mark.parametrize( |
| 65 | + 'webhooks', |
| 66 | + [ |
| 67 | + pytest.param( |
| 68 | + [ |
| 69 | + WebhookCreate( |
| 70 | + event_types=['ACTOR.RUN.SUCCEEDED'], |
| 71 | + condition=WebhookCondition(), |
| 72 | + request_url='https://example.com/run-succeeded', |
| 73 | + idempotency_key='some-key', |
| 74 | + ignore_ssl_errors=True, |
| 75 | + do_not_retry=True, |
| 76 | + ), |
| 77 | + ], |
| 78 | + id='webhook-create-model', |
| 79 | + ), |
| 80 | + pytest.param( |
| 81 | + [ |
| 82 | + { |
| 83 | + 'event_types': ['ACTOR.RUN.SUCCEEDED'], |
| 84 | + 'request_url': 'https://example.com/run-succeeded', |
| 85 | + 'idempotency_key': 'some-key', |
| 86 | + 'ignore_ssl_errors': True, |
| 87 | + 'do_not_retry': True, |
| 88 | + }, |
| 89 | + ], |
| 90 | + id='snake-case-dict', |
| 91 | + ), |
| 92 | + pytest.param( |
| 93 | + [ |
| 94 | + { |
| 95 | + 'eventTypes': ['ACTOR.RUN.SUCCEEDED'], |
| 96 | + 'requestUrl': 'https://example.com/run-succeeded', |
| 97 | + 'idempotencyKey': 'some-key', |
| 98 | + 'ignoreSslErrors': True, |
| 99 | + 'doNotRetry': True, |
| 100 | + }, |
| 101 | + ], |
| 102 | + id='camel-case-dict', |
| 103 | + ), |
| 104 | + ], |
| 105 | +) |
| 106 | +def test_encode_webhooks_to_base64_keeps_adhoc_fields(webhooks: WebhooksList) -> None: |
| 107 | + """Test that the idempotency key and the SSL/retry flags survive the projection for every accepted shape.""" |
| 108 | + result = encode_webhooks_to_base64(webhooks) |
| 109 | + |
| 110 | + assert result is not None |
| 111 | + assert json.loads(b64decode(result)) == [ |
| 112 | + { |
| 113 | + 'eventTypes': ['ACTOR.RUN.SUCCEEDED'], |
| 114 | + 'requestUrl': 'https://example.com/run-succeeded', |
| 115 | + 'idempotencyKey': 'some-key', |
| 116 | + 'ignoreSslErrors': True, |
| 117 | + 'doNotRetry': True, |
| 118 | + } |
| 119 | + ] |
| 120 | + |
| 121 | + |
61 | 122 | def test_encode_webhooks_to_base64_from_dicts() -> None: |
62 | 123 | """Test that encode_webhooks_to_base64 accepts plain dicts typed as WebhookRepresentationDict.""" |
63 | 124 | webhooks: list[WebhookRepresentationDict] = [ |
|
0 commit comments