Skip to content

Commit ae1f880

Browse files
authored
Merge pull request #992 from planetlabs/issue969bis
Add CLI support for subs publishing stages and time range types
2 parents abb65a4 + 354fd45 commit ae1f880

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
2.1.0 (TBD)
22

3+
- Support for publishing stages and time range types has been added to the
4+
subscriptions CLI (#992).
35
- The --cloudconfig option of the request command of the orders CLI has been
46
superseded by a new --delivery option, with --cloudconfig left as an alias.
57
New --archive-type, --archive-filename, and --single-archive options to

planet/cli/subscriptions.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ def request(name,
301301
'--filter',
302302
type=types.JSON(),
303303
help='Search filter. Can be a string, filename, or - for stdin.')
304+
@click.option(
305+
'--publishing-stage',
306+
'publishing_stages',
307+
type=click.Choice(["preview", "standard", "finalized"]),
308+
multiple=True,
309+
help=("Subscribe to results at a particular publishing stage. Multiple "
310+
"instances of this option are allowed."))
311+
@click.option('--time-range-type',
312+
type=click.Choice(["acquired", "published"]),
313+
help="Subscribe by acquisition time or time of publication.")
304314
@pretty
305315
def request_catalog(item_types,
306316
asset_types,
@@ -309,15 +319,20 @@ def request_catalog(item_types,
309319
end_time,
310320
rrule,
311321
filter,
322+
publishing_stages,
323+
time_range_type,
312324
pretty):
313325
"""Generate a subscriptions request catalog source description."""
314-
res = subscription_request.catalog_source(item_types,
315-
asset_types,
316-
geometry,
317-
start_time,
318-
end_time=end_time,
319-
rrule=rrule,
320-
filter=filter)
326+
res = subscription_request.catalog_source(
327+
item_types,
328+
asset_types,
329+
geometry,
330+
start_time,
331+
end_time=end_time,
332+
rrule=rrule,
333+
filter=filter,
334+
publishing_stages=publishing_stages,
335+
time_range_type=time_range_type)
321336
echo_json(res, pretty)
322337

323338

tests/integration/test_subscriptions_cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
TODO: tests for 3 options of the planet-subscriptions-results command.
1313
1414
"""
15+
import itertools
1516
import json
1617

1718
from click.testing import CliRunner
@@ -356,3 +357,46 @@ def test_request_pv_success(invoke, geom_geojson):
356357
source = json.loads(result.output)
357358
assert source["type"] == "biomass_proxy"
358359
assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10"
360+
361+
362+
@pytest.mark.parametrize(
363+
# Test all the combinations of the three options plus some with dupes.
364+
"publishing_stages",
365+
list(
366+
itertools.chain.from_iterable(
367+
itertools.combinations(["preview", "standard", "finalized"], i)
368+
for i in range(1, 4))) + [("preview", "preview"),
369+
("preview", "finalized", "preview")])
370+
def test_catalog_source_publishing_stages(invoke,
371+
geom_geojson,
372+
publishing_stages):
373+
"""Catalog source publishing stages are configured."""
374+
result = invoke([
375+
'request-catalog',
376+
'--item-types=PSScene',
377+
'--asset-types=ortho_analytic_4b',
378+
f"--geometry={json.dumps(geom_geojson)}",
379+
'--start-time=2021-03-01T00:00:00',
380+
] + [f'--publishing-stage={stage}' for stage in publishing_stages])
381+
382+
assert result.exit_code == 0 # success.
383+
req = json.loads(result.output)
384+
assert req['parameters']['publishing_stages'] == list(
385+
set(publishing_stages))
386+
387+
388+
@pytest.mark.parametrize("time_range_type", ["acquired", "published"])
389+
def test_catalog_source_time_range_type(invoke, geom_geojson, time_range_type):
390+
"""Catalog source time range type is configured."""
391+
result = invoke([
392+
'request-catalog',
393+
'--item-types=PSScene',
394+
'--asset-types=ortho_analytic_4b',
395+
f"--geometry={json.dumps(geom_geojson)}",
396+
'--start-time=2021-03-01T00:00:00',
397+
f'--time-range-type={time_range_type}',
398+
])
399+
400+
assert result.exit_code == 0 # success.
401+
req = json.loads(result.output)
402+
assert req['parameters']['time_range_type'] == time_range_type

0 commit comments

Comments
 (0)