Skip to content

Fix notifications entry layout #917

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

Merged
merged 2 commits into from
Apr 13, 2023
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
20 changes: 18 additions & 2 deletions planet/order_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Functionality for preparing order details for use in creating an order"""
from __future__ import annotations # https://stackoverflow.com/a/33533514
import logging
from typing import Optional, Any, Dict, List
from typing import Optional, Any, Dict, List, Union

from . import geojson, specs
from .exceptions import ClientError
Expand Down Expand Up @@ -143,7 +143,23 @@ def notifications(email: Optional[bool] = None,
webhook_per_order: Request a single webhook call per order instead
of one call per each delivered item.
'''
return dict((k, v) for k, v in locals().items() if v)
notifications_dict: Dict[str, Union[dict, bool]] = {}

if webhook_url:
webhook_dict: Dict[str, Union[str, bool]] = {
'url': webhook_url,
}
if webhook_per_order is not None:
wpo: bool = webhook_per_order
webhook_dict['per_order'] = wpo

notifications_dict['webhook'] = webhook_dict

if email is not None:
val: bool = email
notifications_dict['email'] = val

return notifications_dict


def delivery(archive_type: Optional[str] = None,
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_order_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def test_build_request():
}
}
notifications = {
'email': 'email',
'webhook_url': 'webhookurl',
'webhook_per_order': True
'email': 'email', 'webhook': {
'url': 'webhookurl', 'per_order': True
}
}
order_type = 'partial'
tool = {'bandmath': 'jsonstring'}
Expand Down Expand Up @@ -119,11 +119,11 @@ def test_product():

def test_notifications():
notifications_config = order_request.notifications(
email='email', webhook_url='webhookurl', webhook_per_order=True)
email=True, webhook_url='webhookurl', webhook_per_order=True)
expected = {
'email': 'email',
'webhook_url': 'webhookurl',
'webhook_per_order': True
'email': True, 'webhook': {
'url': 'webhookurl', 'per_order': True
}
}
assert notifications_config == expected

Expand Down