Skip to content
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__ = "sahand.seifi@gmail.com"
__version__ = "1.1.0"
__version__ = "1.2.0"
5 changes: 5 additions & 0 deletions notificationapi_python_server_sdk/notificationapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ async def identify_user(params):
custom_auth = 'Basic ' + base64.b64encode(f'{__client_id}:{user_id}:{hashed_user_id_base64}'.encode()).decode()

await request('POST', f'users/{urllib.parse.quote(user_id)}', params, custom_auth)


async def query_logs(params):
response = await request("POST", "logs/query", params)
return response
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.1.0
current_version = 1.2.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.1.0",
version="1.2.0",
zip_safe=False,
)
84 changes: 84 additions & 0 deletions tests/test_notificationapi_query_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/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"
api_paths = {
"query_logs": f"https://api.notificationapi.com/{client_id}/logs/query",
}

query_logs_params = {
"dateRangeFilter": {
"startTime": 1719600830559,
"endTime": 1719600840559
},
"notificationFilter": ["order_tracking"],
"channelFilter": ["EMAIL"],
"userFilter": ["abcd-1234"],
"statusFilter": ["SUCCESS"],
"trackingIds": ["172cf2f4-18cd-4f1f-b2ac-e50c7d71891c"],
"requestFilter": ['request.mergeTags.item="Krabby Patty Burger"'],
"envIdFilter": ["6ok6imq9unr2budgiebjdaa6oi"]
}


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
("query_logs", query_logs_params),
],
)
async def test_makes_one_post_api_call(respx_mock, func, params):
route = respx_mock.post(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",
[
("query_logs", query_logs_params),
],
)
async def test_passes_params_as_json_body(respx_mock, func, params):
route = respx_mock.post(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


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
("query_logs", query_logs_params),
],
)
async def test_logs_on_202(respx_mock, caplog, func, params):
respx_mock.post(api_paths[func]).mock(return_value=Response(202))
notificationapi.init(client_id, client_secret)
await getattr(notificationapi, func)(params)
assert "NotificationAPI request ignored." in caplog.text


@pytest.mark.asyncio
@pytest.mark.parametrize(
"func,params",
[
("query_logs", query_logs_params),
],
)
async def test_logs_and_throws_on_500(respx_mock, caplog, func, params):
respx_mock.post(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