Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasadi committed Nov 11, 2023
1 parent 382d867 commit 098f5b3
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 140 deletions.
4 changes: 3 additions & 1 deletion notificationapi_python_server_sdk/notificationapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def set_user_preferences(params):
"user_preferences/%s" % (params["userId"]),
params["userPreferences"],
)


def identify_user(params):
user_id = params.pop('id')

Expand All @@ -84,4 +86,4 @@ def identify_user(params):

custom_auth = 'Basic ' + base64.b64encode(f'{__client_id}:{user_id}:{hashed_user_id_base64}'.encode()).decode()

request('POST', f'users/{urllib.parse.quote(user_id)}', params, custom_auth)
request('POST', f'users/{urllib.parse.quote(user_id)}', params, custom_auth)
282 changes: 143 additions & 139 deletions tests/test_notificationapi_identify_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
]},
),
],
)
Expand All @@ -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"
}
}
}
]},
),
],
)
Expand All @@ -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"
}
}
}
]},
),
],
)
Expand All @@ -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"
}
}
}
]},
),
],
)
Expand Down

0 comments on commit 098f5b3

Please sign in to comment.