From 71cb7c814d11dcd56412f395834ef9651cffedfc Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 11 Aug 2022 15:02:04 -0400 Subject: [PATCH 01/11] Added STAC option to request. --- planet/cli/orders.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index 12b642e71..28cafd67c 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -263,6 +263,12 @@ async def create(ctx, request: str, pretty): type=types.JSON(), help="""Credentials for cloud storage provider to enable cloud delivery of data. Can be a json string, filename, or '-' for stdin.""") +@click.option( + '--stac', + default=False, + is_flag=True, + help='Request metadata to be in SpatioTemporal Asset Catalog (STAC) format.' +) @pretty async def request(ctx, name, @@ -273,6 +279,7 @@ async def request(ctx, item_type, email, cloudconfig, + stac, pretty): """Generate an order request. @@ -309,6 +316,7 @@ async def request(ctx, products=[product], delivery=delivery, notifications=notifications, - tools=tools) + tools=tools, + stac=stac) echo_json(request, pretty) From 7f3ff5d03427c83d8d7bd305776351ee00a9f96c Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 11 Aug 2022 15:03:33 -0400 Subject: [PATCH 02/11] Added a metadata section with a STAC field to the Create Order request. --- planet/order_request.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/planet/order_request.py b/planet/order_request.py index 104b02812..71dfbaea1 100644 --- a/planet/order_request.py +++ b/planet/order_request.py @@ -28,7 +28,8 @@ def build_request(name: str, delivery: dict = None, notifications: dict = None, order_type: str = None, - tools: List[dict] = None) -> dict: + tools: List[dict] = None, + stac: dict = None) -> dict: '''Prepare an order request. ```python @@ -86,6 +87,9 @@ def build_request(name: str, if tools: details['tools'] = tools + if stac: + details['metadata'] = {'stac': {}} + return details From 4231e9c2f19c5e154260eed6f5f8d6e75a3ced46 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Mon, 15 Aug 2022 09:44:53 -0400 Subject: [PATCH 03/11] Added STAC to build_request test. --- tests/unit/test_order_request.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_order_request.py b/tests/unit/test_order_request.py index 0953e4e67..d0b2f0086 100644 --- a/tests/unit/test_order_request.py +++ b/tests/unit/test_order_request.py @@ -52,13 +52,15 @@ def test_build_request(): } order_type = 'partial' tool = {'band_math': 'jsonstring'} + stac = {'stac': {}} request = order_request.build_request('test_name', [product], subscription_id=subscription_id, delivery=delivery, notifications=notifications, order_type=order_type, - tools=[tool]) + tools=[tool], + stac=True) expected = { 'name': 'test_name', 'products': [product], @@ -66,7 +68,8 @@ def test_build_request(): 'delivery': delivery, 'notifications': notifications, 'order_type': order_type, - 'tools': [tool] + 'tools': [tool], + 'metadata': stac } assert request == expected @@ -77,7 +80,8 @@ def test_build_request(): delivery=delivery, notifications=notifications, order_type=order_type, - tools=[tool]) + tools=[tool], + stac=True) def test_product(): From 1e7b892d5e23194dcc3aa2e9a89b1d8f2289af9b Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Mon, 15 Aug 2022 09:53:05 -0400 Subject: [PATCH 04/11] Added test for orders request. --- tests/integration/test_orders_cli.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/integration/test_orders_cli.py b/tests/integration/test_orders_cli.py index 11eb711ba..f531af0cd 100644 --- a/tests/integration/test_orders_cli.py +++ b/tests/integration/test_orders_cli.py @@ -652,3 +652,31 @@ def test_cli_orders_request_tools(invoke, geom_geojson): tools_json } assert order_request == json.loads(result.output) + + +@respx.mock +def test_cli_orders_request_stac(invoke): + + stac_json = {'stac': {}} + + result = invoke([ + 'request', + '--name=test', + '--id=4500474_2133707_2021-05-20_2419', + '--bundle=analytic', + '--item-type=PSOrthoTile', + '--stac' + ]) + + order_request = { + "name": + "test", + "products": [{ + "item_ids": ["4500474_2133707_2021-05-20_2419"], + "item_type": "PSOrthoTile", + "product_bundle": "analytic", + }], + "metadata": + stac_json + } + assert order_request == json.loads(result.output) From 48c98be5e6213d1d95ed11dc196128eb23c700da Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Tue, 16 Aug 2022 13:12:27 -0400 Subject: [PATCH 05/11] Changed flag from --stac to --no-stac, ie made metadata STAC output by default. --- planet/cli/orders.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index 28cafd67c..751b0a730 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -264,11 +264,11 @@ async def create(ctx, request: str, pretty): help="""Credentials for cloud storage provider to enable cloud delivery of data. Can be a json string, filename, or '-' for stdin.""") @click.option( - '--stac', + '--no-stac', default=False, is_flag=True, - help='Request metadata to be in SpatioTemporal Asset Catalog (STAC) format.' -) + help="""Do not request metadata to be in SpatioTemporal Asset Catalog + (STAC) format.""") @pretty async def request(ctx, name, @@ -279,7 +279,7 @@ async def request(ctx, item_type, email, cloudconfig, - stac, + no_stac, pretty): """Generate an order request. @@ -312,11 +312,16 @@ async def request(ctx, else: delivery = None + if no_stac: + stac_json = {} + else: + stac_json = {'stac': {}} + request = planet.order_request.build_request(name, products=[product], delivery=delivery, notifications=notifications, tools=tools, - stac=stac) + stac=stac_json) echo_json(request, pretty) From 8a8f248a061dffad46e165cfada6d2943694a686 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Tue, 16 Aug 2022 13:13:08 -0400 Subject: [PATCH 06/11] Made metadata input from a variable. --- planet/order_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planet/order_request.py b/planet/order_request.py index 71dfbaea1..911927bc6 100644 --- a/planet/order_request.py +++ b/planet/order_request.py @@ -88,7 +88,7 @@ def build_request(name: str, details['tools'] = tools if stac: - details['metadata'] = {'stac': {}} + details['metadata'] = stac return details From 1e0775b06111b9d552e20a1d5b545b85b49862fc Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Tue, 16 Aug 2022 13:13:47 -0400 Subject: [PATCH 07/11] Changed test for stac metadata to be default. --- tests/unit/test_order_request.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_order_request.py b/tests/unit/test_order_request.py index d0b2f0086..3b8a0ee7c 100644 --- a/tests/unit/test_order_request.py +++ b/tests/unit/test_order_request.py @@ -52,7 +52,7 @@ def test_build_request(): } order_type = 'partial' tool = {'band_math': 'jsonstring'} - stac = {'stac': {}} + stac_json = {'stac': {}} request = order_request.build_request('test_name', [product], subscription_id=subscription_id, @@ -60,7 +60,7 @@ def test_build_request(): notifications=notifications, order_type=order_type, tools=[tool], - stac=True) + stac=stac_json) expected = { 'name': 'test_name', 'products': [product], @@ -69,7 +69,7 @@ def test_build_request(): 'notifications': notifications, 'order_type': order_type, 'tools': [tool], - 'metadata': stac + 'metadata': stac_json } assert request == expected @@ -81,7 +81,7 @@ def test_build_request(): notifications=notifications, order_type=order_type, tools=[tool], - stac=True) + stac=False) def test_product(): From 670af2b9e9ab75bac09888a247fbead59e2eebe1 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Tue, 16 Aug 2022 13:14:17 -0400 Subject: [PATCH 08/11] Changed test for stac metadata to be default. Created pytest fixture for STAC json output. --- tests/integration/test_orders_cli.py | 46 +++++++++++++++++++--------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/integration/test_orders_cli.py b/tests/integration/test_orders_cli.py index f531af0cd..356fc6754 100644 --- a/tests/integration/test_orders_cli.py +++ b/tests/integration/test_orders_cli.py @@ -44,6 +44,11 @@ def _invoke(extra_args, runner=None): return _invoke +@pytest.fixture +def stac_json(): + return {'stac': {}} + + @respx.mock def test_cli_orders_list_basic(invoke, order_descriptions): next_page_url = TEST_ORDERS_URL + '/blob/?page_marker=IAmATest' @@ -451,7 +456,10 @@ def test_cli_orders_create_basic_success(expected_ids, [('4500474_2133707_2021-05-20_2419', ['4500474_2133707_2021-05-20_2419']), ('4500474_2133707_2021-05-20_2419,4500474_2133707_2021-05-20_2420', ['4500474_2133707_2021-05-20_2419', '4500474_2133707_2021-05-20_2420'])]) -def test_cli_orders_request_basic_success(expected_ids, id_string, invoke): +def test_cli_orders_request_basic_success(expected_ids, + id_string, + invoke, + stac_json): result = invoke([ 'request', '--name=test', @@ -469,6 +477,8 @@ def test_cli_orders_request_basic_success(expected_ids, id_string, invoke): "item_type": "PSOrthoTile", "product_bundle": "analytic" }], + "metadata": + stac_json } assert order_request == json.loads(result.output) @@ -503,7 +513,8 @@ def test_cli_orders_request_id_empty(invoke): def test_cli_orders_request_clip_success(geom_fixture, request, invoke, - geom_geojson): + geom_geojson, + stac_json): geom = request.getfixturevalue(geom_fixture) @@ -529,7 +540,9 @@ def test_cli_orders_request_clip_success(geom_fixture, 'clip': { 'aoi': geom_geojson } - }] + }], + "metadata": + stac_json } assert order_request == json.loads(result.output) @@ -566,7 +579,7 @@ def test_cli_orders_request_both_clip_and_tools(invoke, geom_geojson): assert "Specify only one of '--clip' or '--tools'" in result.output -def test_cli_orders_request_cloudconfig(invoke): +def test_cli_orders_request_cloudconfig(invoke, stac_json): config_json = { 'amazon_s3': { 'aws_access_key_id': 'aws_access_key_id', @@ -596,12 +609,14 @@ def test_cli_orders_request_cloudconfig(invoke): "product_bundle": "analytic", }], "delivery": - config_json + config_json, + "metadata": + stac_json } assert order_request == json.loads(result.output) -def test_cli_orders_request_email(invoke): +def test_cli_orders_request_email(invoke, stac_json): result = invoke([ 'request', '--name=test', @@ -621,14 +636,16 @@ def test_cli_orders_request_email(invoke): "product_bundle": "analytic", }], "notifications": { - "email": True - } + "email": True, + }, + "metadata": + stac_json } assert order_request == json.loads(result.output) @respx.mock -def test_cli_orders_request_tools(invoke, geom_geojson): +def test_cli_orders_request_tools(invoke, geom_geojson, stac_json): tools_json = [{'clip': {'aoi': geom_geojson}}, {'composite': {}}] result = invoke([ @@ -649,23 +666,22 @@ def test_cli_orders_request_tools(invoke, geom_geojson): "product_bundle": "analytic", }], "tools": - tools_json + tools_json, + "metadata": + stac_json } assert order_request == json.loads(result.output) @respx.mock -def test_cli_orders_request_stac(invoke): - - stac_json = {'stac': {}} +def test_cli_orders_request_stac(invoke, stac_json): result = invoke([ 'request', '--name=test', '--id=4500474_2133707_2021-05-20_2419', '--bundle=analytic', - '--item-type=PSOrthoTile', - '--stac' + '--item-type=PSOrthoTile' ]) order_request = { From 84d2e5423afa563005678e770d9f5aba2a7d2adb Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 17 Aug 2022 10:12:16 -0400 Subject: [PATCH 09/11] Changed test to test for --no-stac flag. --- tests/integration/test_orders_cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_orders_cli.py b/tests/integration/test_orders_cli.py index 356fc6754..f47c6bb13 100644 --- a/tests/integration/test_orders_cli.py +++ b/tests/integration/test_orders_cli.py @@ -674,14 +674,15 @@ def test_cli_orders_request_tools(invoke, geom_geojson, stac_json): @respx.mock -def test_cli_orders_request_stac(invoke, stac_json): +def test_cli_orders_request_no_stac(invoke): result = invoke([ 'request', '--name=test', '--id=4500474_2133707_2021-05-20_2419', '--bundle=analytic', - '--item-type=PSOrthoTile' + '--item-type=PSOrthoTile', + '--no-stac' ]) order_request = { @@ -691,8 +692,6 @@ def test_cli_orders_request_stac(invoke, stac_json): "item_ids": ["4500474_2133707_2021-05-20_2419"], "item_type": "PSOrthoTile", "product_bundle": "analytic", - }], - "metadata": - stac_json + }] } assert order_request == json.loads(result.output) From 5cbb6dbd67a72e7a5ed6ca81d9b332a027948098 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 17 Aug 2022 10:26:09 -0400 Subject: [PATCH 10/11] Fixed STAC input for build_request. --- tests/unit/test_order_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_order_request.py b/tests/unit/test_order_request.py index 3b8a0ee7c..01633571e 100644 --- a/tests/unit/test_order_request.py +++ b/tests/unit/test_order_request.py @@ -81,7 +81,7 @@ def test_build_request(): notifications=notifications, order_type=order_type, tools=[tool], - stac=False) + stac=stac_json) def test_product(): From affba48d659055fe102fe088278246479ac1b6c6 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 17 Aug 2022 14:29:06 -0400 Subject: [PATCH 11/11] Made stac flag a boolean flag. --- planet/cli/orders.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index 751b0a730..73138d54a 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -264,8 +264,8 @@ async def create(ctx, request: str, pretty): help="""Credentials for cloud storage provider to enable cloud delivery of data. Can be a json string, filename, or '-' for stdin.""") @click.option( - '--no-stac', - default=False, + '--stac/--no-stac', + default=True, is_flag=True, help="""Do not request metadata to be in SpatioTemporal Asset Catalog (STAC) format.""") @@ -279,7 +279,7 @@ async def request(ctx, item_type, email, cloudconfig, - no_stac, + stac, pretty): """Generate an order request. @@ -312,10 +312,10 @@ async def request(ctx, else: delivery = None - if no_stac: - stac_json = {} - else: + if stac: stac_json = {'stac': {}} + else: + stac_json = {} request = planet.order_request.build_request(name, products=[product],