|
11 | 11 | if TYPE_CHECKING: |
12 | 12 | from pytest_httpserver import HTTPServer |
13 | 13 |
|
14 | | - from apify_client._typeddicts import RequestDraftDict |
| 14 | + from apify_client._typeddicts import RequestDraftDeleteDict, RequestDraftDict |
15 | 15 |
|
16 | 16 | _PARTIALLY_ADDED_BATCH_RESPONSE_CONTENT = """{ |
17 | 17 | "data": { |
@@ -117,3 +117,33 @@ def test_batch_processed_partially_sync(httpserver: HTTPServer) -> None: |
117 | 117 | assert requests[0]['unique_key'] in {request.unique_key for request in batch_response.processed_requests} |
118 | 118 | assert len(batch_response.unprocessed_requests) == 1 |
119 | 119 | assert batch_response.unprocessed_requests[0].unique_key == requests[1]['unique_key'] |
| 120 | + |
| 121 | + |
| 122 | +_BATCH_DELETE_RESPONSE_CONTENT = """{"data": {"processedRequests": [], "unprocessedRequests": []}}""" |
| 123 | + |
| 124 | + |
| 125 | +def test_batch_delete_requests_accepts_unique_key_only_dict_sync(httpserver: HTTPServer) -> None: |
| 126 | + """`RequestDraftDelete` is one of `{id} | {uniqueKey}`. A dict with only `unique_key` must validate |
| 127 | + against the right variant — not `RequestDraft`, which would require `url`.""" |
| 128 | + server_url = httpserver.url_for('/').removesuffix('/') |
| 129 | + client = ApifyClient(token='placeholder_token', api_url=server_url, api_public_url=server_url) |
| 130 | + httpserver.expect_oneshot_request(re.compile(r'.*'), method='DELETE').respond_with_data( |
| 131 | + status=200, response_data=_BATCH_DELETE_RESPONSE_CONTENT |
| 132 | + ) |
| 133 | + requests: list[RequestDraftDeleteDict] = [{'unique_key': 'delete-1'}] |
| 134 | + rq_client = client.request_queue(request_queue_id='whatever') |
| 135 | + |
| 136 | + rq_client.batch_delete_requests(requests=requests) |
| 137 | + |
| 138 | + |
| 139 | +async def test_batch_delete_requests_accepts_unique_key_only_dict_async(httpserver: HTTPServer) -> None: |
| 140 | + """Async counterpart of `test_batch_delete_requests_accepts_unique_key_only_dict_sync`.""" |
| 141 | + server_url = httpserver.url_for('/').removesuffix('/') |
| 142 | + client = ApifyClientAsync(token='placeholder_token', api_url=server_url, api_public_url=server_url) |
| 143 | + httpserver.expect_oneshot_request(re.compile(r'.*'), method='DELETE').respond_with_data( |
| 144 | + status=200, response_data=_BATCH_DELETE_RESPONSE_CONTENT |
| 145 | + ) |
| 146 | + requests: list[RequestDraftDeleteDict] = [{'unique_key': 'delete-1'}] |
| 147 | + rq_client = client.request_queue(request_queue_id='whatever') |
| 148 | + |
| 149 | + await rq_client.batch_delete_requests(requests=requests) |
0 commit comments