33from __future__ import annotations
44
55from datetime import UTC , datetime
6- from typing import TYPE_CHECKING , cast
6+ from typing import TYPE_CHECKING
77
88from ._utils import get_random_resource_name , maybe_await
9+ from apify_client ._models import Actor , Build , ListOfActors , Run
10+ from apify_client ._resource_clients import BuildClient , BuildClientAsync
911
1012if TYPE_CHECKING :
1113 from apify_client import ApifyClient , ApifyClientAsync
12- from apify_client ._models import Actor , Build , ListOfActors , Run
13- from apify_client ._resource_clients import BuildClient , BuildClientAsync
1414
1515
1616async def test_get_public_actor (client : ApifyClient | ApifyClientAsync ) -> None :
1717 """Test getting a public Actor by ID."""
1818 # Use a well-known public actor (Apify's web scraper)
19- result = await maybe_await (client .actor ('apify/web-scraper' ).get ())
20- actor = cast ('Actor' , result )
21-
22- assert actor is not None
19+ actor = await maybe_await (client .actor ('apify/web-scraper' ).get ())
20+ assert isinstance (actor , Actor )
2321 assert actor .id is not None
2422 assert actor .name == 'web-scraper'
2523 assert actor .username == 'apify'
2624
2725
2826async def test_get_actor_by_full_name (client : ApifyClient | ApifyClientAsync ) -> None :
2927 """Test getting an Actor using username/actorname format."""
30- result = await maybe_await (client .actor ('apify/hello-world' ).get ())
31- actor = cast ('Actor' , result )
32-
33- assert actor is not None
28+ actor = await maybe_await (client .actor ('apify/hello-world' ).get ())
29+ assert isinstance (actor , Actor )
3430 assert actor .name == 'hello-world'
3531 assert actor .username == 'apify'
3632
3733
3834async def test_list_actors_my (client : ApifyClient | ApifyClientAsync ) -> None :
3935 """Test listing Actors created by the user."""
40- result = await maybe_await (client .actors ().list (my = True , limit = 10 ))
41- actors_page = cast ('ListOfActors' , result )
42-
43- assert actors_page is not None
36+ actors_page = await maybe_await (client .actors ().list (my = True , limit = 10 ))
37+ assert isinstance (actors_page , ListOfActors )
4438 assert actors_page .items is not None
4539 # User may have 0 actors
4640 assert isinstance (actors_page .items , list )
@@ -49,10 +43,8 @@ async def test_list_actors_my(client: ApifyClient | ApifyClientAsync) -> None:
4943async def test_list_actors_pagination (client : ApifyClient | ApifyClientAsync ) -> None :
5044 """Test listing Actors with pagination parameters."""
5145 # List all actors (public + owned), should return some results
52- result = await maybe_await (client .actors ().list (limit = 5 , offset = 0 ))
53- actors_page = cast ('ListOfActors' , result )
54-
55- assert actors_page is not None
46+ actors_page = await maybe_await (client .actors ().list (limit = 5 , offset = 0 ))
47+ assert isinstance (actors_page , ListOfActors )
5648 assert actors_page .items is not None
5749 assert isinstance (actors_page .items , list )
5850 # Should have at least some actors (public ones exist)
@@ -61,10 +53,8 @@ async def test_list_actors_pagination(client: ApifyClient | ApifyClientAsync) ->
6153
6254async def test_list_actors_sorting (client : ApifyClient | ApifyClientAsync ) -> None :
6355 """Test listing Actors with sorting."""
64- result = await maybe_await (client .actors ().list (limit = 10 , desc = True , sort_by = 'stats.lastRunStartedAt' ))
65- actors_page = cast ('ListOfActors' , result )
66-
67- assert actors_page is not None
56+ actors_page = await maybe_await (client .actors ().list (limit = 10 , desc = True , sort_by = 'stats.lastRunStartedAt' ))
57+ assert isinstance (actors_page , ListOfActors )
6858 assert actors_page .items is not None
6959 assert isinstance (actors_page .items , list )
7060
@@ -82,7 +72,7 @@ async def test_actor_create_update_delete(client: ApifyClient | ApifyClientAsync
8272 actor_name = get_random_resource_name ('actor' )
8373
8474 # Create actor
85- result = await maybe_await (
75+ created_actor = await maybe_await (
8676 client .actors ().create (
8777 name = actor_name ,
8878 title = 'Test Actor' ,
@@ -103,8 +93,7 @@ async def test_actor_create_update_delete(client: ApifyClient | ApifyClientAsync
10393 ],
10494 )
10595 )
106- created_actor = cast ('Actor' , result )
107- assert created_actor is not None
96+ assert isinstance (created_actor , Actor )
10897 assert created_actor .id is not None
10998 assert created_actor .name == actor_name
11099
@@ -114,21 +103,19 @@ async def test_actor_create_update_delete(client: ApifyClient | ApifyClientAsync
114103 # Update actor (only title and description - updating defaultRunOptions requires build to be set)
115104 new_title = 'Updated Test Actor'
116105 new_description = 'Updated description'
117- result = await maybe_await (
106+ updated_actor = await maybe_await (
118107 actor_client .update (
119108 title = new_title ,
120109 description = new_description ,
121110 )
122111 )
123- updated_actor = cast ('Actor' , result )
124- assert updated_actor is not None
112+ assert isinstance (updated_actor , Actor )
125113 assert updated_actor .title == new_title
126114 assert updated_actor .description == new_description
127115
128116 # Verify update persisted
129- result = await maybe_await (actor_client .get ())
130- retrieved_actor = cast ('Actor' , result )
131- assert retrieved_actor is not None
117+ retrieved_actor = await maybe_await (actor_client .get ())
118+ assert isinstance (retrieved_actor , Actor )
132119 assert retrieved_actor .title == new_title
133120
134121 finally :
@@ -146,14 +133,12 @@ async def test_actor_default_build(client: ApifyClient | ApifyClientAsync) -> No
146133 actor_client = client .actor ('apify/hello-world' )
147134
148135 # Get default build client
149- result = await maybe_await (actor_client .default_build ())
150- build_client = cast ('BuildClient | BuildClientAsync' , result )
151- assert build_client is not None
136+ build_client = await maybe_await (actor_client .default_build ())
137+ assert isinstance (build_client , BuildClient | BuildClientAsync )
152138
153139 # Use the returned client to get the build
154- result = await maybe_await (build_client .get ())
155- build = cast ('Build' , result )
156- assert build is not None
140+ build = await maybe_await (build_client .get ())
141+ assert isinstance (build , Build )
157142 assert build .id is not None
158143 assert build .status is not None
159144
@@ -162,19 +147,17 @@ async def test_actor_last_run(client: ApifyClient | ApifyClientAsync) -> None:
162147 """Test getting an Actor's last run."""
163148 # First run an actor to ensure there is a last run
164149 actor_client = client .actor ('apify/hello-world' )
165- result = await maybe_await (actor_client .call ())
166- run = cast ('Run' , result )
167- assert run is not None
150+ run = await maybe_await (actor_client .call ())
151+ assert isinstance (run , Run )
168152
169153 try :
170154 # Get last run client
171155 last_run_client = actor_client .last_run ()
172156 assert last_run_client is not None
173157
174158 # Use the returned client to get the run
175- result = await maybe_await (last_run_client .get ())
176- last_run = cast ('Run' , result )
177- assert last_run is not None
159+ last_run = await maybe_await (last_run_client .get ())
160+ assert isinstance (last_run , Run )
178161 assert last_run .id is not None
179162
180163 finally :
0 commit comments