12
12
if TYPE_CHECKING :
13
13
from apify_client import ApifyClientAsync
14
14
15
- from .conftest import ActorFactory
15
+ from .conftest import ActorFactory , RunActorFunction
16
16
17
17
18
18
async def test_actor_reports_running_on_platform (
19
- apify_client_async : ApifyClientAsync ,
19
+ run_actor : RunActorFunction ,
20
20
make_actor : ActorFactory ,
21
21
) -> None :
22
22
async def main () -> None :
23
23
async with Actor :
24
24
assert Actor .is_at_home () is True
25
25
26
26
actor = await make_actor ('is-at-home' , main_func = main )
27
+ run_result = await run_actor (actor )
27
28
28
- call_result = await actor .call ()
29
- assert call_result is not None
30
-
31
- run_client = apify_client_async .run (call_result ['id' ])
32
- run_result = await run_client .wait_for_finish (wait_secs = 600 )
33
-
34
- assert run_result is not None
35
29
assert run_result ['status' ] == 'SUCCEEDED'
36
30
37
31
38
32
async def test_actor_retrieves_env_vars (
39
- apify_client_async : ApifyClientAsync ,
33
+ run_actor : RunActorFunction ,
40
34
make_actor : ActorFactory ,
41
35
) -> None :
42
36
async def main () -> None :
@@ -56,19 +50,13 @@ async def main() -> None:
56
50
assert len (env_dict .get ('default_request_queue_id' , '' )) == 17
57
51
58
52
actor = await make_actor ('get-env' , main_func = main )
53
+ run_result = await run_actor (actor )
59
54
60
- call_result = await actor .call ()
61
- assert call_result is not None
62
-
63
- run_client = apify_client_async .run (call_result ['id' ])
64
- run_result = await run_client .wait_for_finish (wait_secs = 600 )
65
-
66
- assert run_result is not None
67
55
assert run_result ['status' ] == 'SUCCEEDED'
68
56
69
57
70
58
async def test_actor_creates_new_client_instance (
71
- apify_client_async : ApifyClientAsync ,
59
+ run_actor : RunActorFunction ,
72
60
make_actor : ActorFactory ,
73
61
) -> None :
74
62
async def main () -> None :
@@ -86,14 +74,8 @@ async def main() -> None:
86
74
await kv_store_client .set_record ('OUTPUT' , 'TESTING-OUTPUT' )
87
75
88
76
actor = await make_actor ('new-client' , main_func = main )
77
+ run_result = await run_actor (actor )
89
78
90
- call_result = await actor .call ()
91
- assert call_result is not None
92
-
93
- run_client = apify_client_async .run (call_result ['id' ])
94
- run_result = await run_client .wait_for_finish (wait_secs = 600 )
95
-
96
- assert run_result is not None
97
79
assert run_result ['status' ] == 'SUCCEEDED'
98
80
99
81
output_record = await actor .last_run ().key_value_store ().get_record ('OUTPUT' )
@@ -102,7 +84,7 @@ async def main() -> None:
102
84
103
85
104
86
async def test_actor_sets_status_message (
105
- apify_client_async : ApifyClientAsync ,
87
+ run_actor : RunActorFunction ,
106
88
make_actor : ActorFactory ,
107
89
) -> None :
108
90
async def main () -> None :
@@ -111,32 +93,21 @@ async def main() -> None:
111
93
await Actor .set_status_message ('testing-status-message' , ** actor_input )
112
94
113
95
actor = await make_actor ('set-status-message' , main_func = main )
96
+ run_result_1 = await run_actor (actor )
114
97
115
- call_result = await actor .call ()
116
- assert call_result is not None
117
-
118
- run_client = apify_client_async .run (call_result ['id' ])
119
- run_result = await run_client .wait_for_finish (wait_secs = 600 )
120
-
121
- assert run_result is not None
122
- assert run_result ['status' ] == 'SUCCEEDED'
123
- assert run_result ['statusMessage' ] == 'testing-status-message'
124
- assert run_result ['isStatusMessageTerminal' ] is None
125
-
126
- call_result_2 = await actor .call (run_input = {'is_terminal' : True })
127
- assert call_result_2 is not None
98
+ assert run_result_1 ['status' ] == 'SUCCEEDED'
99
+ assert run_result_1 ['statusMessage' ] == 'testing-status-message'
100
+ assert run_result_1 ['isStatusMessageTerminal' ] is None
128
101
129
- run_client_2 = apify_client_async .run (call_result_2 ['id' ])
130
- run_result_2 = await run_client_2 .wait_for_finish (wait_secs = 600 )
102
+ run_result_2 = await run_actor (actor , run_input = {'is_terminal' : True })
131
103
132
- assert run_result_2 is not None
133
104
assert run_result_2 ['status' ] == 'SUCCEEDED'
134
105
assert run_result_2 ['statusMessage' ] == 'testing-status-message'
135
106
assert run_result_2 ['isStatusMessageTerminal' ] is True
136
107
137
108
138
109
async def test_actor_starts_another_actor_instance (
139
- apify_client_async : ApifyClientAsync ,
110
+ run_actor : RunActorFunction ,
140
111
make_actor : ActorFactory ,
141
112
) -> None :
142
113
async def main_inner () -> None :
@@ -166,13 +137,11 @@ async def main_outer() -> None:
166
137
inner_actor_id = (await inner_actor .get () or {})['id' ]
167
138
test_value = crypto_random_object_id ()
168
139
169
- outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
170
- assert outer_call_result is not None
171
-
172
- run_client_outer = apify_client_async .run (outer_call_result ['id' ])
173
- run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 600 )
140
+ run_result_outer = await run_actor (
141
+ outer_actor ,
142
+ run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id },
143
+ )
174
144
175
- assert run_result_outer is not None
176
145
assert run_result_outer ['status' ] == 'SUCCEEDED'
177
146
178
147
await inner_actor .last_run ().wait_for_finish (wait_secs = 600 )
@@ -183,7 +152,7 @@ async def main_outer() -> None:
183
152
184
153
185
154
async def test_actor_calls_another_actor (
186
- apify_client_async : ApifyClientAsync ,
155
+ run_actor : RunActorFunction ,
187
156
make_actor : ActorFactory ,
188
157
) -> None :
189
158
async def main_inner () -> None :
@@ -213,13 +182,11 @@ async def main_outer() -> None:
213
182
inner_actor_id = (await inner_actor .get () or {})['id' ]
214
183
test_value = crypto_random_object_id ()
215
184
216
- outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
217
- assert outer_call_result is not None
218
-
219
- run_client_outer = apify_client_async .run (outer_call_result ['id' ])
220
- run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 600 )
185
+ run_result_outer = await run_actor (
186
+ outer_actor ,
187
+ run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id },
188
+ )
221
189
222
- assert run_result_outer is not None
223
190
assert run_result_outer ['status' ] == 'SUCCEEDED'
224
191
225
192
await inner_actor .last_run ().wait_for_finish (wait_secs = 600 )
@@ -231,6 +198,7 @@ async def main_outer() -> None:
231
198
232
199
async def test_actor_calls_task (
233
200
apify_client_async : ApifyClientAsync ,
201
+ run_actor : RunActorFunction ,
234
202
make_actor : ActorFactory ,
235
203
) -> None :
236
204
async def main_inner () -> None :
@@ -265,13 +233,11 @@ async def main_outer() -> None:
265
233
task_input = {'test_value' : test_value },
266
234
)
267
235
268
- outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_task_id' : task ['id' ]})
269
- assert outer_call_result is not None
270
-
271
- run_client_outer = apify_client_async .run (outer_call_result ['id' ])
272
- run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 600 )
236
+ run_result_outer = await run_actor (
237
+ outer_actor ,
238
+ run_input = {'test_value' : test_value , 'inner_task_id' : task ['id' ]},
239
+ )
273
240
274
- assert run_result_outer is not None
275
241
assert run_result_outer ['status' ] == 'SUCCEEDED'
276
242
277
243
await inner_actor .last_run ().wait_for_finish (wait_secs = 600 )
@@ -284,7 +250,7 @@ async def main_outer() -> None:
284
250
285
251
286
252
async def test_actor_aborts_another_actor_run (
287
- apify_client_async : ApifyClientAsync ,
253
+ run_actor : RunActorFunction ,
288
254
make_actor : ActorFactory ,
289
255
) -> None :
290
256
async def main_inner () -> None :
@@ -307,13 +273,11 @@ async def main_outer() -> None:
307
273
308
274
inner_run_id = (await inner_actor .start ())['id' ]
309
275
310
- outer_call_result = await outer_actor .call (run_input = {'inner_run_id' : inner_run_id })
311
- assert outer_call_result is not None
312
-
313
- run_client_outer = apify_client_async .run (outer_call_result ['id' ])
314
- run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 600 )
276
+ run_result_outer = await run_actor (
277
+ outer_actor ,
278
+ run_input = {'inner_run_id' : inner_run_id },
279
+ )
315
280
316
- assert run_result_outer is not None
317
281
assert run_result_outer ['status' ] == 'SUCCEEDED'
318
282
319
283
await inner_actor .last_run ().wait_for_finish (wait_secs = 600 )
@@ -326,7 +290,7 @@ async def main_outer() -> None:
326
290
327
291
328
292
async def test_actor_metamorphs_into_another_actor (
329
- apify_client_async : ApifyClientAsync ,
293
+ run_actor : RunActorFunction ,
330
294
make_actor : ActorFactory ,
331
295
) -> None :
332
296
async def main_inner () -> None :
@@ -366,13 +330,11 @@ async def main_outer() -> None:
366
330
inner_actor_id = (await inner_actor .get () or {})['id' ]
367
331
test_value = crypto_random_object_id ()
368
332
369
- outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
370
- assert outer_call_result is not None
371
-
372
- run_client_outer = apify_client_async .run (outer_call_result ['id' ])
373
- run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 600 )
333
+ run_result_outer = await run_actor (
334
+ outer_actor ,
335
+ run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id },
336
+ )
374
337
375
- assert run_result_outer is not None
376
338
assert run_result_outer ['status' ] == 'SUCCEEDED'
377
339
378
340
outer_run_key_value_store = outer_actor .last_run ().key_value_store ()
@@ -388,7 +350,7 @@ async def main_outer() -> None:
388
350
389
351
390
352
async def test_actor_reboots_successfully (
391
- apify_client_async : ApifyClientAsync ,
353
+ run_actor : RunActorFunction ,
392
354
make_actor : ActorFactory ,
393
355
) -> None :
394
356
async def main () -> None :
@@ -406,13 +368,11 @@ async def main() -> None:
406
368
407
369
actor = await make_actor ('actor_rebooter' , main_func = main )
408
370
409
- call_result = await actor .call (run_input = {'counter_key' : 'reboot_counter' })
410
- assert call_result is not None
411
-
412
- run_client = apify_client_async .run (call_result ['id' ])
413
- run_result = await run_client .wait_for_finish (wait_secs = 600 )
371
+ run_result = await run_actor (
372
+ actor ,
373
+ run_input = {'counter_key' : 'reboot_counter' },
374
+ )
414
375
415
- assert run_result is not None
416
376
assert run_result ['status' ] == 'SUCCEEDED'
417
377
418
378
not_written_value = await actor .last_run ().key_value_store ().get_record ('THIS_KEY_SHOULD_NOT_BE_WRITTEN' )
@@ -424,7 +384,7 @@ async def main() -> None:
424
384
425
385
426
386
async def test_actor_adds_webhook_and_receives_event (
427
- apify_client_async : ApifyClientAsync ,
387
+ run_actor : RunActorFunction ,
428
388
make_actor : ActorFactory ,
429
389
) -> None :
430
390
async def main_server () -> None :
@@ -487,13 +447,11 @@ async def main_client() -> None:
487
447
server_actor_initialized = await server_actor .last_run ().key_value_store ().get_record ('INITIALIZED' )
488
448
await asyncio .sleep (1 )
489
449
490
- ac_call_result = await client_actor .call (run_input = {'server_actor_container_url' : server_actor_container_url })
491
- assert ac_call_result is not None
492
-
493
- ac_run_client = apify_client_async .run (ac_call_result ['id' ])
494
- ac_run_result = await ac_run_client .wait_for_finish (wait_secs = 600 )
450
+ ac_run_result = await run_actor (
451
+ client_actor ,
452
+ run_input = {'server_actor_container_url' : server_actor_container_url },
453
+ )
495
454
496
- assert ac_run_result is not None
497
455
assert ac_run_result ['status' ] == 'SUCCEEDED'
498
456
499
457
sa_run_result = await server_actor .last_run ().wait_for_finish (wait_secs = 600 )
0 commit comments