Repository: planetlabs/planet-client-python

Issue:
Add publishing_stages to catalog source parameters
It's a list of choices from "preview", "standard", or "finalized". See https://developers.planet.com/docs/subscriptions/reference/#tag/subscriptions/operation/createSubscription.

Discussion:

Patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index a78e118..fc85a88 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,7 @@
 2.1.0 (TBD)
 
+- Support for publishing stages and time range types has been added to the
+  subscriptions CLI (#992).
 - The --cloudconfig option of the request command of the orders CLI has been
   superseded by a new --delivery option, with --cloudconfig left as an alias.
   New --archive-type, --archive-filename, and --single-archive options to
diff --git a/planet/cli/subscriptions.py b/planet/cli/subscriptions.py
index eebc1a8..f3f1b37 100644
--- a/planet/cli/subscriptions.py
+++ b/planet/cli/subscriptions.py
@@ -301,6 +301,16 @@ def request(name,
     '--filter',
     type=types.JSON(),
     help='Search filter.  Can be a string, filename, or - for stdin.')
+@click.option(
+    '--publishing-stage',
+    'publishing_stages',
+    type=click.Choice(["preview", "standard", "finalized"]),
+    multiple=True,
+    help=("Subscribe to results at a particular publishing stage. Multiple "
+          "instances of this option are allowed."))
+@click.option('--time-range-type',
+              type=click.Choice(["acquired", "published"]),
+              help="Subscribe by acquisition time or time of publication.")
 @pretty
 def request_catalog(item_types,
                     asset_types,
@@ -309,15 +319,20 @@ def request_catalog(item_types,
                     end_time,
                     rrule,
                     filter,
+                    publishing_stages,
+                    time_range_type,
                     pretty):
     """Generate a subscriptions request catalog source description."""
-    res = subscription_request.catalog_source(item_types,
-                                              asset_types,
-                                              geometry,
-                                              start_time,
-                                              end_time=end_time,
-                                              rrule=rrule,
-                                              filter=filter)
+    res = subscription_request.catalog_source(
+        item_types,
+        asset_types,
+        geometry,
+        start_time,
+        end_time=end_time,
+        rrule=rrule,
+        filter=filter,
+        publishing_stages=publishing_stages,
+        time_range_type=time_range_type)
     echo_json(res, pretty)
 
 


Test patch:
diff --git a/tests/integration/test_subscriptions_cli.py b/tests/integration/test_subscriptions_cli.py
index a1b3cea..1e40eb9 100644
--- a/tests/integration/test_subscriptions_cli.py
+++ b/tests/integration/test_subscriptions_cli.py
@@ -12,6 +12,7 @@ There are 6 subscriptions commands:
 TODO: tests for 3 options of the planet-subscriptions-results command.
 
 """
+import itertools
 import json
 
 from click.testing import CliRunner
@@ -356,3 +357,46 @@ def test_request_pv_success(invoke, geom_geojson):
     source = json.loads(result.output)
     assert source["type"] == "biomass_proxy"
     assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10"
+
+
+@pytest.mark.parametrize(
+    # Test all the combinations of the three options plus some with dupes.
+    "publishing_stages",
+    list(
+        itertools.chain.from_iterable(
+            itertools.combinations(["preview", "standard", "finalized"], i)
+            for i in range(1, 4))) + [("preview", "preview"),
+                                      ("preview", "finalized", "preview")])
+def test_catalog_source_publishing_stages(invoke,
+                                          geom_geojson,
+                                          publishing_stages):
+    """Catalog source publishing stages are configured."""
+    result = invoke([
+        'request-catalog',
+        '--item-types=PSScene',
+        '--asset-types=ortho_analytic_4b',
+        f"--geometry={json.dumps(geom_geojson)}",
+        '--start-time=2021-03-01T00:00:00',
+    ] + [f'--publishing-stage={stage}' for stage in publishing_stages])
+
+    assert result.exit_code == 0  # success.
+    req = json.loads(result.output)
+    assert req['parameters']['publishing_stages'] == list(
+        set(publishing_stages))
+
+
+@pytest.mark.parametrize("time_range_type", ["acquired", "published"])
+def test_catalog_source_time_range_type(invoke, geom_geojson, time_range_type):
+    """Catalog source time range type is configured."""
+    result = invoke([
+        'request-catalog',
+        '--item-types=PSScene',
+        '--asset-types=ortho_analytic_4b',
+        f"--geometry={json.dumps(geom_geojson)}",
+        '--start-time=2021-03-01T00:00:00',
+        f'--time-range-type={time_range_type}',
+    ])
+
+    assert result.exit_code == 0  # success.
+    req = json.loads(result.output)
+    assert req['parameters']['time_range_type'] == time_range_type