Skip to content

Add STAC output orders request #676

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 11 commits into from
Aug 17, 2022
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
15 changes: 14 additions & 1 deletion planet/cli/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/--no-stac',
default=True,
is_flag=True,
help="""Do not request metadata to be in SpatioTemporal Asset Catalog
(STAC) format.""")
@pretty
async def request(ctx,
name,
Expand All @@ -273,6 +279,7 @@ async def request(ctx,
item_type,
email,
cloudconfig,
stac,
pretty):
"""Generate an order request.

Expand Down Expand Up @@ -305,10 +312,16 @@ async def request(ctx,
else:
delivery = None

if stac:
stac_json = {'stac': {}}
else:
stac_json = {}

request = planet.order_request.build_request(name,
products=[product],
delivery=delivery,
notifications=notifications,
tools=tools)
tools=tools,
stac=stac_json)

echo_json(request, pretty)
6 changes: 5 additions & 1 deletion planet/order_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +87,9 @@ def build_request(name: str,
if tools:
details['tools'] = tools

if stac:
details['metadata'] = stac

return details


Expand Down
63 changes: 53 additions & 10 deletions tests/integration/test_orders_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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([
Expand All @@ -649,6 +666,32 @@ 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_no_stac(invoke):

result = invoke([
'request',
'--name=test',
'--id=4500474_2133707_2021-05-20_2419',
'--bundle=analytic',
'--item-type=PSOrthoTile',
'--no-stac'
])

order_request = {
"name":
"test",
"products": [{
"item_ids": ["4500474_2133707_2021-05-20_2419"],
"item_type": "PSOrthoTile",
"product_bundle": "analytic",
}]
}
assert order_request == json.loads(result.output)
10 changes: 7 additions & 3 deletions tests/unit/test_order_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,24 @@ def test_build_request():
}
order_type = 'partial'
tool = {'band_math': 'jsonstring'}
stac_json = {'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=stac_json)
expected = {
'name': 'test_name',
'products': [product],
'subscription_id': subscription_id,
'delivery': delivery,
'notifications': notifications,
'order_type': order_type,
'tools': [tool]
'tools': [tool],
'metadata': stac_json
}
assert request == expected

Expand All @@ -77,7 +80,8 @@ def test_build_request():
delivery=delivery,
notifications=notifications,
order_type=order_type,
tools=[tool])
tools=[tool],
stac=stac_json)


def test_product():
Expand Down