Skip to content

Commit a5d9bd7

Browse files
authored
Merge pull request #14 from notificationapi-com/UnO3asvD/1746-update-all-back-end-notificationapi-sdks-to-schedule-update-delete
Chore: update_schedule and delete_schedule
2 parents 63ce8a1 + d0e7b57 commit a5d9bd7

File tree

6 files changed

+189
-3
lines changed

6 files changed

+189
-3
lines changed

notificationapi_python_server_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """Sahand Seifi"""
44
__email__ = "[email protected]"
5-
__version__ = "1.0.1"
5+
__version__ = "1.1.0"

notificationapi_python_server_sdk/notificationapi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ async def delete_sub_notification(params):
7272
)
7373

7474

75+
async def update_schedule(params):
76+
await request(
77+
"PATCH",
78+
"schedule/%s"
79+
% (params["tracking_id"]),
80+
params["send_request"],
81+
)
82+
83+
84+
async def delete_schedule(params):
85+
await request(
86+
"DELETE",
87+
"schedule/%s"
88+
% (params["tracking_id"]),
89+
)
90+
91+
7592
async def set_user_preferences(params):
7693
await request(
7794
"POST",

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.1
2+
current_version = 1.1.0
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@
5252
test_suite="tests",
5353
tests_require=test_requirements,
5454
url="https://github.com/notificationapi-com/notificationapi_python_server_sdk",
55-
version="1.0.1",
55+
version="1.1.0",
5656
zip_safe=False,
5757
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
3+
"""Tests for `notificationapi_python_server_sdk` package."""
4+
5+
import pytest
6+
from httpx import Response
7+
from notificationapi_python_server_sdk import notificationapi
8+
9+
client_id = "client_id"
10+
client_secret = "client_secret"
11+
tracking_id = "tracking_id"
12+
api_paths = {
13+
"delete_schedule": f"https://api.notificationapi.com/{client_id}/schedule/{tracking_id}"
14+
}
15+
16+
17+
@pytest.mark.asyncio
18+
@pytest.mark.parametrize(
19+
"func,params",
20+
[
21+
(
22+
"delete_schedule",
23+
{
24+
"tracking_id": tracking_id,
25+
},
26+
),
27+
],
28+
)
29+
async def test_makes_one_delete_api_call(respx_mock, func, params):
30+
route = respx_mock.delete(api_paths[func]).mock(return_value=Response(200))
31+
notificationapi.init(client_id, client_secret)
32+
await getattr(notificationapi, func)(params)
33+
assert route.called
34+
35+
36+
@pytest.mark.asyncio
37+
@pytest.mark.parametrize(
38+
"func,params",
39+
[
40+
(
41+
"delete_schedule",
42+
{
43+
"tracking_id": tracking_id,
44+
},
45+
),
46+
],
47+
)
48+
async def test_uses_basic_authorization(respx_mock, func, params):
49+
route = respx_mock.delete(api_paths[func]).mock(return_value=Response(200))
50+
notificationapi.init(client_id, client_secret)
51+
await getattr(notificationapi, func)(params)
52+
assert route.calls.last.request.headers["Authorization"] == "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="
53+
54+
55+
@pytest.mark.asyncio
56+
@pytest.mark.parametrize(
57+
"func,params",
58+
[
59+
(
60+
"delete_schedule",
61+
{
62+
"tracking_id": tracking_id,
63+
},
64+
),
65+
],
66+
)
67+
async def test_logs_and_throws_on_500(respx_mock, caplog, func, params):
68+
respx_mock.delete(api_paths[func]).mock(return_value=Response(500, text="big oof 500"))
69+
notificationapi.init(client_id, client_secret)
70+
await getattr(notificationapi, func)(params)
71+
assert "NotificationAPI request failed. Response: big oof 500" in caplog.text
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python
2+
3+
"""Tests for `notificationapi_python_server_sdk` package."""
4+
5+
import pytest
6+
import json
7+
from httpx import Response
8+
from notificationapi_python_server_sdk import notificationapi
9+
10+
client_id = "client_id"
11+
client_secret = "client_secret"
12+
tracking_id = "tracking_id"
13+
send_request = {
14+
'notificationId': 'notification_id'
15+
}
16+
api_paths = {
17+
"update_schedule": f"https://api.notificationapi.com/{client_id}/schedule/{tracking_id}",
18+
}
19+
20+
21+
@pytest.mark.asyncio
22+
@pytest.mark.parametrize(
23+
"func,params",
24+
[
25+
(
26+
"update_schedule",
27+
{
28+
"tracking_id": tracking_id,
29+
"send_request": send_request,
30+
},
31+
),
32+
],
33+
)
34+
async def test_makes_one_patch_api_call(respx_mock, func, params):
35+
route = respx_mock.patch(api_paths[func]).mock(return_value=Response(200))
36+
notificationapi.init(client_id, client_secret)
37+
await getattr(notificationapi, func)(params)
38+
assert route.called
39+
40+
41+
@pytest.mark.asyncio
42+
@pytest.mark.parametrize(
43+
"func,params",
44+
[
45+
(
46+
"update_schedule",
47+
{
48+
"tracking_id": tracking_id,
49+
"send_request": send_request,
50+
},
51+
),
52+
],
53+
)
54+
async def test_uses_basic_authorization(respx_mock, func, params):
55+
route = respx_mock.patch(api_paths[func]).mock(return_value=Response(200))
56+
notificationapi.init(client_id, client_secret)
57+
await getattr(notificationapi, func)(params)
58+
assert route.calls.last.request.headers["Authorization"] == "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="
59+
60+
61+
@pytest.mark.asyncio
62+
@pytest.mark.parametrize(
63+
"func,params",
64+
[
65+
(
66+
"update_schedule",
67+
{
68+
"tracking_id": tracking_id,
69+
"send_request": send_request,
70+
},
71+
),
72+
],
73+
)
74+
async def test_passes_send_request_as_json_body(respx_mock, func, params):
75+
route = respx_mock.patch(api_paths[func]).mock(return_value=Response(200))
76+
notificationapi.init(client_id, client_secret)
77+
await getattr(notificationapi, func)(params)
78+
assert json.loads(route.calls.last.request.content) == params["send_request"]
79+
80+
81+
@pytest.mark.asyncio
82+
@pytest.mark.parametrize(
83+
"func,params",
84+
[
85+
(
86+
"update_schedule",
87+
{
88+
"tracking_id": tracking_id,
89+
"send_request": send_request,
90+
},
91+
),
92+
],
93+
)
94+
async def test_logs_and_throws_on_500(respx_mock, caplog, func, params):
95+
respx_mock.patch(api_paths[func]).mock(return_value=Response(500, text="big oof 500"))
96+
notificationapi.init(client_id, client_secret)
97+
await getattr(notificationapi, func)(params)
98+
assert "NotificationAPI request failed. Response: big oof 500" in caplog.text

0 commit comments

Comments
 (0)