|
2 | 2 |
|
3 | 3 | import json |
4 | 4 | import os |
5 | | -from dataclasses import dataclass |
6 | 5 | from typing import TYPE_CHECKING |
7 | 6 |
|
8 | 7 | import pytest |
|
12 | 11 | TOKEN_ENV_VAR, |
13 | 12 | TOKEN_ENV_VAR_2, |
14 | 13 | DatasetFixture, |
| 14 | + HttpClientClasses, |
15 | 15 | KvsFixture, |
16 | 16 | get_crypto_random_object_id, |
17 | 17 | ) |
18 | 18 | from apify_client import ApifyClient, ApifyClientAsync |
19 | 19 | from apify_client._consts import DEFAULT_API_URL |
20 | 20 | from apify_client._utils.crypto import create_hmac_signature, create_storage_content_signature |
21 | 21 | from apify_client.http_clients import ( |
22 | | - HttpClient, |
23 | | - HttpClientAsync, |
24 | 22 | HttpxHttpClient, |
25 | 23 | HttpxHttpClientAsync, |
26 | 24 | ImpitHttpClient, |
|
31 | 29 | from collections.abc import AsyncGenerator, Generator |
32 | 30 |
|
33 | 31 |
|
34 | | -@dataclass(frozen=True) |
35 | | -class HttpClientClasses: |
36 | | - """Synchronous and asynchronous variants of a built-in HTTP client.""" |
37 | | - |
38 | | - sync: type[HttpClient] |
39 | | - async_: type[HttpClientAsync] |
40 | | - |
41 | | - |
42 | | -DEFAULT_HTTP_CLIENT_CLASSES = HttpClientClasses(sync=ImpitHttpClient, async_=ImpitHttpClientAsync) |
43 | | -"""HTTP clients the live-API suite runs with unless a test asks for another transport.""" |
44 | | - |
45 | | -ALL_HTTP_CLIENT_CLASSES = [ |
46 | | - pytest.param(DEFAULT_HTTP_CLIENT_CLASSES, id='impit'), |
47 | | - pytest.param(HttpClientClasses(sync=HttpxHttpClient, async_=HttpxHttpClientAsync), id='httpx'), |
48 | | -] |
49 | | -"""Every built-in HTTP client, for tests that exercise transport behavior rather than an API resource.""" |
50 | | - |
51 | | - |
52 | 32 | @pytest.fixture(scope='session') |
53 | 33 | def api_token() -> str: |
54 | 34 | """Primary test user API token.""" |
@@ -126,18 +106,17 @@ def test_kvs_of_another_user(api_token_2: str) -> Generator[KvsFixture]: |
126 | 106 | kvs_client.delete() |
127 | 107 |
|
128 | 108 |
|
129 | | -@pytest.fixture |
| 109 | +@pytest.fixture( |
| 110 | + params=[ |
| 111 | + pytest.param(HttpClientClasses(sync=ImpitHttpClient, async_=ImpitHttpClientAsync), id='impit'), |
| 112 | + pytest.param(HttpClientClasses(sync=HttpxHttpClient, async_=HttpxHttpClientAsync), id='httpx'), |
| 113 | + ] |
| 114 | +) |
130 | 115 | def http_client_classes(request: pytest.FixtureRequest) -> HttpClientClasses: |
131 | | - """Return the sync and async classes of the HTTP client the test runs with. |
132 | | -
|
133 | | - Defaults to Impit so the live-API suite isn't multiplied by every transport. A transport-level test opts into |
134 | | - the full matrix with `@pytest.mark.parametrize('http_client_classes', ALL_HTTP_CLIENT_CLASSES, indirect=True)`. |
135 | | - """ |
136 | | - if not hasattr(request, 'param'): |
137 | | - return DEFAULT_HTTP_CLIENT_CLASSES |
138 | | - |
139 | | - assert isinstance(request.param, HttpClientClasses) |
140 | | - return request.param |
| 116 | + """Return the sync and async classes of the HTTP client the test runs with, once per built-in transport.""" |
| 117 | + classes = request.param |
| 118 | + assert isinstance(classes, HttpClientClasses) |
| 119 | + return classes |
141 | 120 |
|
142 | 121 |
|
143 | 122 | @pytest.fixture(params=['sync', 'async']) |
|
0 commit comments