-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
146 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,47 +12,48 @@ | |
|
||
client_id = "client_id" | ||
client_secret = "client_secret" | ||
user_id = "userId" | ||
user_id = "userId" | ||
|
||
|
||
api_paths = { | ||
"identify_user": f"https://api.notificationapi.com/{client_id}/users/{urllib.parse.quote(user_id)}", | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func,params", | ||
[ | ||
( | ||
"identify_user", | ||
{ | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
), | ||
], | ||
) | ||
|
@@ -62,40 +63,41 @@ def test_makes_one_POST_api_call(requests_mock, func, params): | |
getattr(notificationapi, func)(params) | ||
assert requests_mock.call_count == 1 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func,params", | ||
[ | ||
( | ||
"identify_user", | ||
{ | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
), | ||
], | ||
) | ||
|
@@ -109,42 +111,43 @@ def test_uses_custom_authorization(requests_mock, func, params): | |
notificationapi.init(client_id, client_secret) | ||
getattr(notificationapi, func)(params) | ||
assert "Authorization" in requests_mock.last_request.headers | ||
assert requests_mock.last_request.headers["Authorization" ]==custom_auth | ||
assert requests_mock.last_request.headers["Authorization"] == custom_auth | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func,params", | ||
[ | ||
( | ||
"identify_user", | ||
{ | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
), | ||
], | ||
) | ||
|
@@ -153,69 +156,70 @@ def test_passes_data_as_json_body(requests_mock, func, params): | |
notificationapi.init(client_id, client_secret) | ||
getattr(notificationapi, func)(params) | ||
sent_data = requests_mock.last_request.json() | ||
assert sent_data == { | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
assert sent_data == { | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
} | ||
]} | ||
]} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func,params", | ||
[ | ||
( | ||
"identify_user", | ||
{ | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
"id": user_id, | ||
"email": "[email protected]", | ||
"number": "+15005550006", | ||
"pushTokens": [ | ||
{ | ||
"type": "FCM", | ||
"token": "samplePushToken", | ||
"device": { | ||
"app_id": "sample_app_id", | ||
"ad_id": "sample_ad_id", | ||
"device_id": "sample_device_id", | ||
"platform": "sample_platform", | ||
"manufacturer": "sample_manufacturer", | ||
"model": "sample_model" | ||
} | ||
} | ||
], | ||
"webPushTokens": [ | ||
{ | ||
"sub": { | ||
"endpoint": "sample_endpoint", | ||
"keys": { | ||
"p256dh": "sample_p256dh", | ||
"auth": "sample_auth" | ||
} | ||
} | ||
} | ||
]}, | ||
), | ||
], | ||
) | ||
|