Skip to content

Commit 4de63ac

Browse files
authored
Merge pull request #6 from ActivitySmithHQ/test/add-resource-wrapper-tests
test: add wrapper behavior tests
2 parents bc7bd8d + 876cf63 commit 4de63ac

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/test_resources.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from activitysmith.client import ActivitySmith
2+
import activitysmith.client as client_module
3+
4+
5+
class FakePushNotificationsApi:
6+
def __init__(self, _api_client):
7+
self.calls = []
8+
9+
def send_push_notification(self, **kwargs):
10+
self.calls.append(kwargs)
11+
return kwargs
12+
13+
14+
class FakeLiveActivitiesApi:
15+
def __init__(self, _api_client):
16+
self.calls = []
17+
18+
def start_live_activity(self, **kwargs):
19+
self.calls.append(("start", kwargs))
20+
return kwargs
21+
22+
def update_live_activity(self, **kwargs):
23+
self.calls.append(("update", kwargs))
24+
return kwargs
25+
26+
def end_live_activity(self, **kwargs):
27+
self.calls.append(("end", kwargs))
28+
return kwargs
29+
30+
31+
def test_notifications_short_and_legacy_alias(monkeypatch):
32+
monkeypatch.setattr(client_module, "PushNotificationsApi", FakePushNotificationsApi)
33+
monkeypatch.setattr(client_module, "LiveActivitiesApi", FakeLiveActivitiesApi)
34+
35+
client = ActivitySmith(api_key="x")
36+
payload = {"title": "Build Failed"}
37+
38+
short = client.notifications.send(payload)
39+
legacy = client.notifications.send_push_notification(payload)
40+
41+
assert short == {"push_notification_request": payload}
42+
assert legacy == {"push_notification_request": payload}
43+
assert client.notifications._api.calls == [
44+
{"push_notification_request": payload},
45+
{"push_notification_request": payload},
46+
]
47+
48+
49+
def test_live_activities_short_and_legacy_aliases(monkeypatch):
50+
monkeypatch.setattr(client_module, "PushNotificationsApi", FakePushNotificationsApi)
51+
monkeypatch.setattr(client_module, "LiveActivitiesApi", FakeLiveActivitiesApi)
52+
53+
client = ActivitySmith(api_key="x")
54+
start_payload = {
55+
"content_state": {
56+
"title": "Deploy",
57+
"number_of_steps": 4,
58+
"current_step": 1,
59+
"type": "segmented_progress",
60+
}
61+
}
62+
update_payload = {
63+
"activity_id": "act-1",
64+
"content_state": {"title": "Deploy", "current_step": 2},
65+
}
66+
end_payload = {
67+
"activity_id": "act-1",
68+
"content_state": {"title": "Deploy", "current_step": 4},
69+
}
70+
71+
client.live_activities.start(start_payload)
72+
client.live_activities.update(update_payload)
73+
client.live_activities.end(end_payload)
74+
75+
client.live_activities.start_live_activity(start_payload)
76+
client.live_activities.update_live_activity(update_payload)
77+
client.live_activities.end_live_activity(end_payload)
78+
79+
assert client.live_activities._api.calls == [
80+
("start", {"live_activity_start_request": start_payload}),
81+
("update", {"live_activity_update_request": update_payload}),
82+
("end", {"live_activity_end_request": end_payload}),
83+
("start", {"live_activity_start_request": start_payload}),
84+
("update", {"live_activity_update_request": update_payload}),
85+
("end", {"live_activity_end_request": end_payload}),
86+
]

0 commit comments

Comments
 (0)