Skip to content

Commit d4fd250

Browse files
authored
Merge pull request #917 from planetlabs/webhook-916
Fix notifications entry layout
2 parents 7a01159 + 740026a commit d4fd250

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

planet/order_request.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Functionality for preparing order details for use in creating an order"""
1616
from __future__ import annotations # https://stackoverflow.com/a/33533514
1717
import logging
18-
from typing import Optional, Any, Dict, List
18+
from typing import Optional, Any, Dict, List, Union
1919

2020
from . import geojson, specs
2121
from .exceptions import ClientError
@@ -143,7 +143,23 @@ def notifications(email: Optional[bool] = None,
143143
webhook_per_order: Request a single webhook call per order instead
144144
of one call per each delivered item.
145145
'''
146-
return dict((k, v) for k, v in locals().items() if v)
146+
notifications_dict: Dict[str, Union[dict, bool]] = {}
147+
148+
if webhook_url:
149+
webhook_dict: Dict[str, Union[str, bool]] = {
150+
'url': webhook_url,
151+
}
152+
if webhook_per_order is not None:
153+
wpo: bool = webhook_per_order
154+
webhook_dict['per_order'] = wpo
155+
156+
notifications_dict['webhook'] = webhook_dict
157+
158+
if email is not None:
159+
val: bool = email
160+
notifications_dict['email'] = val
161+
162+
return notifications_dict
147163

148164

149165
def delivery(archive_type: Optional[str] = None,

tests/unit/test_order_request.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def test_build_request():
4646
}
4747
}
4848
notifications = {
49-
'email': 'email',
50-
'webhook_url': 'webhookurl',
51-
'webhook_per_order': True
49+
'email': 'email', 'webhook': {
50+
'url': 'webhookurl', 'per_order': True
51+
}
5252
}
5353
order_type = 'partial'
5454
tool = {'bandmath': 'jsonstring'}
@@ -119,11 +119,11 @@ def test_product():
119119

120120
def test_notifications():
121121
notifications_config = order_request.notifications(
122-
email='email', webhook_url='webhookurl', webhook_per_order=True)
122+
email=True, webhook_url='webhookurl', webhook_per_order=True)
123123
expected = {
124-
'email': 'email',
125-
'webhook_url': 'webhookurl',
126-
'webhook_per_order': True
124+
'email': True, 'webhook': {
125+
'url': 'webhookurl', 'per_order': True
126+
}
127127
}
128128
assert notifications_config == expected
129129

0 commit comments

Comments
 (0)