1
1
from __future__ import annotations
2
2
3
- from typing import TYPE_CHECKING
3
+ from typing import TYPE_CHECKING , ClassVar
4
4
5
5
from apify_client import ApifyClientAsync
6
6
from apify_shared .consts import ApifyEnvVars , WebhookEventType
7
7
8
- from apify import Actor
8
+ from apify import Actor , Webhook
9
9
from apify ._actor import _ActorType
10
10
11
11
if TYPE_CHECKING :
@@ -34,11 +34,50 @@ async def test_actor_new_client_config(self: TestActorNewClient, monkeypatch: py
34
34
35
35
36
36
class TestActorCallStartAbortActor :
37
+ FAKE_ACTOR_RUN : ClassVar = {
38
+ 'id' : 'asdfasdf' ,
39
+ 'buildId' : '3ads35' ,
40
+ 'buildNumber' : '3.4.5' ,
41
+ 'actId' : 'actor_id' ,
42
+ 'actorId' : 'actor_id' ,
43
+ 'userId' : 'user_id' ,
44
+ 'startedAt' : '2024-08-08 12:12:44' ,
45
+ 'status' : 'RUNNING' ,
46
+ 'meta' : {'origin' : 'API' },
47
+ 'containerUrl' : 'http://0.0.0.0:3333' ,
48
+ 'defaultDatasetId' : 'dhasdrfughaerguoi' ,
49
+ 'defaultKeyValueStoreId' : 'asjkldhguiofg' ,
50
+ 'defaultRequestQueueId' : 'lkjgklserjghios' ,
51
+ 'stats' : {
52
+ 'inputBodyLen' : 0 ,
53
+ 'restartCount' : 0 ,
54
+ 'resurrectCount' : 0 ,
55
+ 'memAvgBytes' : 0 ,
56
+ 'memMaxBytes' : 0 ,
57
+ 'memCurrentBytes' : 0 ,
58
+ 'cpuAvgUsage' : 0 ,
59
+ 'cpuMaxUsage' : 0 ,
60
+ 'cpuCurrentUsage' : 0 ,
61
+ 'netRxBytes' : 0 ,
62
+ 'netTxBytes' : 0 ,
63
+ 'durationMillis' : 3333 ,
64
+ 'runTimeSecs' : 33 ,
65
+ 'metamorph' : 0 ,
66
+ 'computeUnits' : 4.33 ,
67
+ },
68
+ 'options' : {
69
+ 'build' : '' ,
70
+ 'timeoutSecs' : 44 ,
71
+ 'memoryMbytes' : 4096 ,
72
+ 'diskMbytes' : 16384 ,
73
+ },
74
+ }
75
+
37
76
async def test_actor_call (
38
77
self : TestActorCallStartAbortActor ,
39
78
apify_client_async_patcher : ApifyClientAsyncPatcher ,
40
79
) -> None :
41
- apify_client_async_patcher .patch ('actor' , 'call' , return_value = None )
80
+ apify_client_async_patcher .patch ('actor' , 'call' , return_value = self . FAKE_ACTOR_RUN )
42
81
actor_id = 'some-actor-id'
43
82
44
83
async with Actor :
@@ -52,7 +91,7 @@ async def test_actor_call_task(
52
91
self : TestActorCallStartAbortActor ,
53
92
apify_client_async_patcher : ApifyClientAsyncPatcher ,
54
93
) -> None :
55
- apify_client_async_patcher .patch ('task' , 'call' , return_value = None )
94
+ apify_client_async_patcher .patch ('task' , 'call' , return_value = self . FAKE_ACTOR_RUN )
56
95
task_id = 'some-task-id'
57
96
58
97
async with Actor :
@@ -65,7 +104,7 @@ async def test_actor_start(
65
104
self : TestActorCallStartAbortActor ,
66
105
apify_client_async_patcher : ApifyClientAsyncPatcher ,
67
106
) -> None :
68
- apify_client_async_patcher .patch ('actor' , 'start' , return_value = None )
107
+ apify_client_async_patcher .patch ('actor' , 'start' , return_value = self . FAKE_ACTOR_RUN )
69
108
actor_id = 'some-id'
70
109
71
110
async with Actor :
@@ -78,7 +117,7 @@ async def test_actor_abort(
78
117
self : TestActorCallStartAbortActor ,
79
118
apify_client_async_patcher : ApifyClientAsyncPatcher ,
80
119
) -> None :
81
- apify_client_async_patcher .patch ('run' , 'abort' , return_value = None )
120
+ apify_client_async_patcher .patch ('run' , 'abort' , return_value = self . FAKE_ACTOR_RUN )
82
121
run_id = 'some-run-id'
83
122
84
123
async with Actor :
@@ -119,7 +158,7 @@ async def test_actor_add_webhook_not_work_locally(
119
158
) -> None :
120
159
async with Actor :
121
160
await Actor .add_webhook (
122
- event_types = [WebhookEventType .ACTOR_BUILD_ABORTED ], request_url = 'https://example.com'
161
+ Webhook ( event_types = [WebhookEventType .ACTOR_BUILD_ABORTED ], request_url = 'https://example.com' )
123
162
)
124
163
125
164
assert len (caplog .records ) == 1
0 commit comments