Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: update_schedule and delete_schedule #14

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notificationapi_python_server_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Sahand Seifi"""
__email__ = "[email protected]"
__version__ = "1.0.1"
__version__ = "1.1.0"
17 changes: 17 additions & 0 deletions notificationapi_python_server_sdk/notificationapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ async def delete_sub_notification(params):
)


async def update_schedule(params):
await request(
"PATCH",
"schedule/%s"
% (params["tracking_id"]),
params["send_request"],
)


async def delete_schedule(params):
await request(
"DELETE",
"schedule/%s"
% (params["tracking_id"]),
)


async def set_user_preferences(params):
await request(
"POST",
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.1
current_version = 1.1.0
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/notificationapi-com/notificationapi_python_server_sdk",
version="1.0.1",
version="1.1.0",
zip_safe=False,
)
71 changes: 71 additions & 0 deletions tests/test_notificationapi_deleteSchedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python

"""Tests for `notificationapi_python_server_sdk` package."""

import pytest
from httpx import Response
from notificationapi_python_server_sdk import notificationapi

client_id = "client_id"
client_secret = "client_secret"
tracking_id = "tracking_id"
api_paths = {
"delete_schedule": f"https://api.notificationapi.com/{client_id}/schedule/{tracking_id}"
}


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"delete_schedule",
{
"tracking_id": tracking_id,
},
),
],
)
async def test_makes_one_delete_api_call(respx_mock, func, params):
route = respx_mock.delete(api_paths[func]).mock(return_value=Response(200))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert route.called


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"delete_schedule",
{
"tracking_id": tracking_id,
},
),
],
)
async def test_uses_basic_authorization(respx_mock, func, params):
route = respx_mock.delete(api_paths[func]).mock(return_value=Response(200))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert route.calls.last.request.headers["Authorization"] == "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"delete_schedule",
{
"tracking_id": tracking_id,
},
),
],
)
async def test_logs_and_throws_on_500(respx_mock, caplog, func, params):
respx_mock.delete(api_paths[func]).mock(return_value=Response(500, text="big oof 500"))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert "NotificationAPI request failed. Response: big oof 500" in caplog.text
98 changes: 98 additions & 0 deletions tests/test_notificationapi_updateSchedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python

"""Tests for `notificationapi_python_server_sdk` package."""

import pytest
import json
from httpx import Response
from notificationapi_python_server_sdk import notificationapi

client_id = "client_id"
client_secret = "client_secret"
tracking_id = "tracking_id"
send_request = {
'notificationId': 'notification_id'
}
api_paths = {
"update_schedule": f"https://api.notificationapi.com/{client_id}/schedule/{tracking_id}",
}


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"update_schedule",
{
"tracking_id": tracking_id,
"send_request": send_request,
},
),
],
)
async def test_makes_one_patch_api_call(respx_mock, func, params):
route = respx_mock.patch(api_paths[func]).mock(return_value=Response(200))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert route.called


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"update_schedule",
{
"tracking_id": tracking_id,
"send_request": send_request,
},
),
],
)
async def test_uses_basic_authorization(respx_mock, func, params):
route = respx_mock.patch(api_paths[func]).mock(return_value=Response(200))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert route.calls.last.request.headers["Authorization"] == "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"update_schedule",
{
"tracking_id": tracking_id,
"send_request": send_request,
},
),
],
)
async def test_passes_send_request_as_json_body(respx_mock, func, params):
route = respx_mock.patch(api_paths[func]).mock(return_value=Response(200))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert json.loads(route.calls.last.request.content) == params["send_request"]


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
(
"update_schedule",
{
"tracking_id": tracking_id,
"send_request": send_request,
},
),
],
)
async def test_logs_and_throws_on_500(respx_mock, caplog, func, params):
respx_mock.patch(api_paths[func]).mock(return_value=Response(500, text="big oof 500"))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert "NotificationAPI request failed. Response: big oof 500" in caplog.text
Loading