Skip to content

Commit 7caed86

Browse files
committed
Update unit tests
1 parent 45226a6 commit 7caed86

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

tests/unit/actor/test_actor_helpers.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, ClassVar
44

55
from apify_client import ApifyClientAsync
66
from apify_shared.consts import ApifyEnvVars, WebhookEventType
77

8-
from apify import Actor
8+
from apify import Actor, Webhook
99
from apify._actor import _ActorType
1010

1111
if TYPE_CHECKING:
@@ -34,11 +34,50 @@ async def test_actor_new_client_config(self: TestActorNewClient, monkeypatch: py
3434

3535

3636
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+
3776
async def test_actor_call(
3877
self: TestActorCallStartAbortActor,
3978
apify_client_async_patcher: ApifyClientAsyncPatcher,
4079
) -> 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)
4281
actor_id = 'some-actor-id'
4382

4483
async with Actor:
@@ -52,7 +91,7 @@ async def test_actor_call_task(
5291
self: TestActorCallStartAbortActor,
5392
apify_client_async_patcher: ApifyClientAsyncPatcher,
5493
) -> 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)
5695
task_id = 'some-task-id'
5796

5897
async with Actor:
@@ -65,7 +104,7 @@ async def test_actor_start(
65104
self: TestActorCallStartAbortActor,
66105
apify_client_async_patcher: ApifyClientAsyncPatcher,
67106
) -> 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)
69108
actor_id = 'some-id'
70109

71110
async with Actor:
@@ -78,7 +117,7 @@ async def test_actor_abort(
78117
self: TestActorCallStartAbortActor,
79118
apify_client_async_patcher: ApifyClientAsyncPatcher,
80119
) -> 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)
82121
run_id = 'some-run-id'
83122

84123
async with Actor:
@@ -119,7 +158,7 @@ async def test_actor_add_webhook_not_work_locally(
119158
) -> None:
120159
async with Actor:
121160
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')
123162
)
124163

125164
assert len(caplog.records) == 1

0 commit comments

Comments
 (0)