|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING
|
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | from integration.integration_test_utils import random_resource_name, random_string
|
6 | 8 |
|
| 9 | +from apify_client.clients.resource_clients.request_queue import unique_key_to_request_id |
| 10 | + |
7 | 11 | if TYPE_CHECKING:
|
8 | 12 | from apify_client import ApifyClient, ApifyClientAsync
|
9 | 13 |
|
@@ -113,3 +117,38 @@ async def test_request_batch_operations(self, apify_client_async: ApifyClientAsy
|
113 | 117 | assert len(requests_in_queue2['items']) == 25 - len(delete_response['processedRequests'])
|
114 | 118 |
|
115 | 119 | await queue.delete()
|
| 120 | + |
| 121 | + |
| 122 | +def test_unique_key_to_request_id_length() -> None: |
| 123 | + unique_key = 'exampleKey123' |
| 124 | + request_id = unique_key_to_request_id(unique_key, request_id_length=15) |
| 125 | + assert len(request_id) == 15, 'Request ID should have the correct length.' |
| 126 | + |
| 127 | + |
| 128 | +def test_unique_key_to_request_id_consistency() -> None: |
| 129 | + unique_key = 'consistentKey' |
| 130 | + request_id_1 = unique_key_to_request_id(unique_key) |
| 131 | + request_id_2 = unique_key_to_request_id(unique_key) |
| 132 | + assert request_id_1 == request_id_2, 'The same unique key should generate consistent request IDs.' |
| 133 | + |
| 134 | + |
| 135 | +@pytest.mark.parametrize( |
| 136 | + ('unique_key', 'expected_request_id'), |
| 137 | + [ |
| 138 | + ('abc', 'ungWv48BzpBQUDe'), |
| 139 | + ('uniqueKey', 'xiWPs083cree7mH'), |
| 140 | + ('', '47DEQpj8HBSaTIm'), |
| 141 | + ('测试中文', 'lKPdJkdvw8MXEUp'), |
| 142 | + ('test+/=', 'XZRQjhoG0yjfnYD'), |
| 143 | + ], |
| 144 | + ids=[ |
| 145 | + 'basic_abc', |
| 146 | + 'keyword_uniqueKey', |
| 147 | + 'empty_string', |
| 148 | + 'non_ascii_characters', |
| 149 | + 'url_unsafe_characters', |
| 150 | + ], |
| 151 | +) |
| 152 | +def test_unique_key_to_request_id_matches_known_values(unique_key: str, expected_request_id: str) -> None: |
| 153 | + request_id = unique_key_to_request_id(unique_key) |
| 154 | + assert request_id == expected_request_id, f'Unique key "{unique_key}" should produce the expected request ID.' |
0 commit comments