22
33from __future__ import annotations
44
5- from typing import TYPE_CHECKING
5+ import os
66
7- from .._utils import maybe_await
7+ from .._utils import API_URL_ENV_VAR , maybe_await
8+ from apify_client import ApifyClient , ApifyClientAsync
9+ from apify_client ._consts import DEFAULT_API_URL
810from apify_client ._models import UserPrivateInfo , UserPublicInfo
9-
10- if TYPE_CHECKING :
11- from apify_client import ApifyClient , ApifyClientAsync
11+ from apify_client .http_clients import ImpitHttpClient , ImpitHttpClientAsync
1212
1313
1414async def test_apify_client (client : ApifyClient | ApifyClientAsync ) -> None :
@@ -17,3 +17,24 @@ async def test_apify_client(client: ApifyClient | ApifyClientAsync) -> None:
1717 me = await maybe_await (user_client .get ())
1818 assert isinstance (me , UserPrivateInfo | UserPublicInfo )
1919 assert me .username is not None
20+
21+
22+ async def test_plain_constructor_reaches_the_api (client_type : str , api_token : str ) -> None :
23+ """The plain constructor - the form users write - reaches the API with the HTTP client it builds itself.
24+
25+ The rest of the suite injects a transport through `with_custom_http_client` to run against every built-in
26+ implementation, which leaves the default construction path untested against the live API.
27+ """
28+ api_url = os .getenv (API_URL_ENV_VAR ) or DEFAULT_API_URL
29+
30+ if client_type == 'sync' :
31+ sync_client = ApifyClient (api_token , api_url = api_url )
32+ assert isinstance (sync_client .http_client , ImpitHttpClient )
33+ assert sync_client .user ('me' ).get () is not None
34+ sync_client .http_client .close ()
35+ return
36+
37+ async_client = ApifyClientAsync (api_token , api_url = api_url )
38+ assert isinstance (async_client .http_client , ImpitHttpClientAsync )
39+ assert await async_client .user ('me' ).get () is not None
40+ await async_client .http_client .aclose ()
0 commit comments