Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasadi committed Jul 11, 2024
1 parent 4cce88b commit e236bd5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
5 changes: 3 additions & 2 deletions notificationapi_python_server_sdk/notificationapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ async def query_logs(params):
response = await request("POST", "logs/query", params)
return response


async def update_in_app_notification(user_id, params):

hashed_user_id = hashlib.sha256((__client_secret + user_id).encode()).digest()
hashed_user_id_base64 = base64.b64encode(hashed_user_id).decode()
custom_auth = 'Basic ' + base64.b64encode(f'{__client_id}:{user_id}:{hashed_user_id_base64}'.encode()).decode()

return await request('PATCH', f'users/{user_id}/notifications/INAPP_WEB', params, custom_auth)
102 changes: 52 additions & 50 deletions tests/test_notificationapi_update_in_app_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
client_secret = "client_secret"
user_id = "userId"


api_paths = {
"update_in_app_notification": f"https://api.notificationapi.com/{client_id}/users/{urllib.parse.quote(user_id)}/notifications/INAPP_WEB",
}
Expand All @@ -26,16 +25,17 @@
[
(
"update_in_app_notification",
(user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
(
user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
),
),
],
Expand All @@ -52,16 +52,17 @@ async def test_makes_one_patch_api_call(respx_mock, func, params):
[
(
"update_in_app_notification",
(user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
(
user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
),
),
],
Expand All @@ -84,16 +85,17 @@ async def test_uses_custom_authorization(respx_mock, func, params):
[
(
"update_in_app_notification",
(user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
(
user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
),
),
],
Expand All @@ -104,32 +106,32 @@ async def test_passes_data_as_json_body(respx_mock, func, params):
await getattr(notificationapi, func)(*params)
sent_data = json.loads(route.calls.last.request.content)
assert sent_data == {
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}

}
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}


@pytest.mark.parametrize(
"func,params",
[
(
"update_in_app_notification",
(user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
(
user_id,
{
"trackingIds": ["sampleTrackingId"],
"opened": "1970-01-01T00:00:00.000Z",
"clicked": "1970-01-01T00:00:00.000Z",
"archived": "1970-01-01T00:00:00.000Z",
"actioned1": "1970-01-01T00:00:00.000Z",
"actioned2": "1970-01-01T00:00:00.000Z",
"reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"}
}
),
),
],
Expand Down

0 comments on commit e236bd5

Please sign in to comment.