diff --git a/planet/order_request.py b/planet/order_request.py index 4f5410cc..f7ab105f 100644 --- a/planet/order_request.py +++ b/planet/order_request.py @@ -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 @@ -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, diff --git a/tests/unit/test_order_request.py b/tests/unit/test_order_request.py index 48f3be00..1b21c222 100644 --- a/tests/unit/test_order_request.py +++ b/tests/unit/test_order_request.py @@ -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'} @@ -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