Skip to content

Commit 87c8b0a

Browse files
Merge pull request #676 from planetlabs/add_stac_output_orders_request
Add STAC metadata output for orders request
2 parents 09878a9 + affba48 commit 87c8b0a

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

planet/cli/orders.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ async def create(ctx, request: str, pretty):
263263
type=types.JSON(),
264264
help="""Credentials for cloud storage provider to enable cloud delivery of
265265
data. Can be a json string, filename, or '-' for stdin.""")
266+
@click.option(
267+
'--stac/--no-stac',
268+
default=True,
269+
is_flag=True,
270+
help="""Do not request metadata to be in SpatioTemporal Asset Catalog
271+
(STAC) format.""")
266272
@pretty
267273
async def request(ctx,
268274
name,
@@ -273,6 +279,7 @@ async def request(ctx,
273279
item_type,
274280
email,
275281
cloudconfig,
282+
stac,
276283
pretty):
277284
"""Generate an order request.
278285
@@ -305,10 +312,16 @@ async def request(ctx,
305312
else:
306313
delivery = None
307314

315+
if stac:
316+
stac_json = {'stac': {}}
317+
else:
318+
stac_json = {}
319+
308320
request = planet.order_request.build_request(name,
309321
products=[product],
310322
delivery=delivery,
311323
notifications=notifications,
312-
tools=tools)
324+
tools=tools,
325+
stac=stac_json)
313326

314327
echo_json(request, pretty)

planet/order_request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def build_request(name: str,
2828
delivery: dict = None,
2929
notifications: dict = None,
3030
order_type: str = None,
31-
tools: List[dict] = None) -> dict:
31+
tools: List[dict] = None,
32+
stac: dict = None) -> dict:
3233
'''Prepare an order request.
3334
3435
```python
@@ -86,6 +87,9 @@ def build_request(name: str,
8687
if tools:
8788
details['tools'] = tools
8889

90+
if stac:
91+
details['metadata'] = stac
92+
8993
return details
9094

9195

tests/integration/test_orders_cli.py

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def _invoke(extra_args, runner=None):
4444
return _invoke
4545

4646

47+
@pytest.fixture
48+
def stac_json():
49+
return {'stac': {}}
50+
51+
4752
@respx.mock
4853
def test_cli_orders_list_basic(invoke, order_descriptions):
4954
next_page_url = TEST_ORDERS_URL + '/blob/?page_marker=IAmATest'
@@ -451,7 +456,10 @@ def test_cli_orders_create_basic_success(expected_ids,
451456
[('4500474_2133707_2021-05-20_2419', ['4500474_2133707_2021-05-20_2419']),
452457
('4500474_2133707_2021-05-20_2419,4500474_2133707_2021-05-20_2420',
453458
['4500474_2133707_2021-05-20_2419', '4500474_2133707_2021-05-20_2420'])])
454-
def test_cli_orders_request_basic_success(expected_ids, id_string, invoke):
459+
def test_cli_orders_request_basic_success(expected_ids,
460+
id_string,
461+
invoke,
462+
stac_json):
455463
result = invoke([
456464
'request',
457465
'--name=test',
@@ -469,6 +477,8 @@ def test_cli_orders_request_basic_success(expected_ids, id_string, invoke):
469477
"item_type": "PSOrthoTile",
470478
"product_bundle": "analytic"
471479
}],
480+
"metadata":
481+
stac_json
472482
}
473483
assert order_request == json.loads(result.output)
474484

@@ -503,7 +513,8 @@ def test_cli_orders_request_id_empty(invoke):
503513
def test_cli_orders_request_clip_success(geom_fixture,
504514
request,
505515
invoke,
506-
geom_geojson):
516+
geom_geojson,
517+
stac_json):
507518

508519
geom = request.getfixturevalue(geom_fixture)
509520

@@ -529,7 +540,9 @@ def test_cli_orders_request_clip_success(geom_fixture,
529540
'clip': {
530541
'aoi': geom_geojson
531542
}
532-
}]
543+
}],
544+
"metadata":
545+
stac_json
533546
}
534547
assert order_request == json.loads(result.output)
535548

@@ -566,7 +579,7 @@ def test_cli_orders_request_both_clip_and_tools(invoke, geom_geojson):
566579
assert "Specify only one of '--clip' or '--tools'" in result.output
567580

568581

569-
def test_cli_orders_request_cloudconfig(invoke):
582+
def test_cli_orders_request_cloudconfig(invoke, stac_json):
570583
config_json = {
571584
'amazon_s3': {
572585
'aws_access_key_id': 'aws_access_key_id',
@@ -596,12 +609,14 @@ def test_cli_orders_request_cloudconfig(invoke):
596609
"product_bundle": "analytic",
597610
}],
598611
"delivery":
599-
config_json
612+
config_json,
613+
"metadata":
614+
stac_json
600615
}
601616
assert order_request == json.loads(result.output)
602617

603618

604-
def test_cli_orders_request_email(invoke):
619+
def test_cli_orders_request_email(invoke, stac_json):
605620
result = invoke([
606621
'request',
607622
'--name=test',
@@ -621,14 +636,16 @@ def test_cli_orders_request_email(invoke):
621636
"product_bundle": "analytic",
622637
}],
623638
"notifications": {
624-
"email": True
625-
}
639+
"email": True,
640+
},
641+
"metadata":
642+
stac_json
626643
}
627644
assert order_request == json.loads(result.output)
628645

629646

630647
@respx.mock
631-
def test_cli_orders_request_tools(invoke, geom_geojson):
648+
def test_cli_orders_request_tools(invoke, geom_geojson, stac_json):
632649
tools_json = [{'clip': {'aoi': geom_geojson}}, {'composite': {}}]
633650

634651
result = invoke([
@@ -649,6 +666,32 @@ def test_cli_orders_request_tools(invoke, geom_geojson):
649666
"product_bundle": "analytic",
650667
}],
651668
"tools":
652-
tools_json
669+
tools_json,
670+
"metadata":
671+
stac_json
672+
}
673+
assert order_request == json.loads(result.output)
674+
675+
676+
@respx.mock
677+
def test_cli_orders_request_no_stac(invoke):
678+
679+
result = invoke([
680+
'request',
681+
'--name=test',
682+
'--id=4500474_2133707_2021-05-20_2419',
683+
'--bundle=analytic',
684+
'--item-type=PSOrthoTile',
685+
'--no-stac'
686+
])
687+
688+
order_request = {
689+
"name":
690+
"test",
691+
"products": [{
692+
"item_ids": ["4500474_2133707_2021-05-20_2419"],
693+
"item_type": "PSOrthoTile",
694+
"product_bundle": "analytic",
695+
}]
653696
}
654697
assert order_request == json.loads(result.output)

tests/unit/test_order_request.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,24 @@ def test_build_request():
5252
}
5353
order_type = 'partial'
5454
tool = {'band_math': 'jsonstring'}
55+
stac_json = {'stac': {}}
5556

5657
request = order_request.build_request('test_name', [product],
5758
subscription_id=subscription_id,
5859
delivery=delivery,
5960
notifications=notifications,
6061
order_type=order_type,
61-
tools=[tool])
62+
tools=[tool],
63+
stac=stac_json)
6264
expected = {
6365
'name': 'test_name',
6466
'products': [product],
6567
'subscription_id': subscription_id,
6668
'delivery': delivery,
6769
'notifications': notifications,
6870
'order_type': order_type,
69-
'tools': [tool]
71+
'tools': [tool],
72+
'metadata': stac_json
7073
}
7174
assert request == expected
7275

@@ -77,7 +80,8 @@ def test_build_request():
7780
delivery=delivery,
7881
notifications=notifications,
7982
order_type=order_type,
80-
tools=[tool])
83+
tools=[tool],
84+
stac=stac_json)
8185

8286

8387
def test_product():

0 commit comments

Comments
 (0)