From b01d8be107585083aae5fefefa7a3e7bcbfbbd8c Mon Sep 17 00:00:00 2001 From: asonnenschein Date: Wed, 19 Mar 2025 07:25:52 -0400 Subject: [PATCH 1/6] make subscription source type optional --- planet/cli/subscriptions.py | 2 +- planet/subscription_request.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/planet/cli/subscriptions.py b/planet/cli/subscriptions.py index dc9c2ef5..2b160298 100644 --- a/planet/cli/subscriptions.py +++ b/planet/cli/subscriptions.py @@ -483,7 +483,7 @@ def request_catalog(item_types, @translate_exceptions @click.option( '--var-type', - required=True, + required=False, help='A Planetary Variable type. See documentation for all available types.' ) @click.option( diff --git a/planet/subscription_request.py b/planet/subscription_request.py index 7cf3eefb..71c36a8d 100644 --- a/planet/subscription_request.py +++ b/planet/subscription_request.py @@ -281,7 +281,7 @@ def catalog_source( if time_range_type: parameters['time_range_type'] = time_range_type - return {"type": "catalog", "parameters": parameters} + return {"parameters": parameters} def planetary_variable_source( @@ -369,7 +369,10 @@ def planetary_variable_source( except AttributeError: raise ClientError('Could not convert end_time to an iso string') - return {"type": var_type, "parameters": parameters} + source: dict[str, Any] = {"parameters": parameters} + if var_type: + source["type"] = var_type + return source def _datetime_to_rfc3339(value: datetime) -> str: From 72288ead06b5b9290162e104597821711a9d9030 Mon Sep 17 00:00:00 2001 From: asonnenschein Date: Wed, 19 Mar 2025 07:58:07 -0400 Subject: [PATCH 2/6] fix failing tests --- tests/integration/test_subscriptions_cli.py | 1 - tests/unit/test_subscription_request.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/tests/integration/test_subscriptions_cli.py b/tests/integration/test_subscriptions_cli.py index 7b071b28..ee69521f 100644 --- a/tests/integration/test_subscriptions_cli.py +++ b/tests/integration/test_subscriptions_cli.py @@ -370,7 +370,6 @@ def test_request_base_clip_to_source(geom_fixture, request, invoke): def test_request_catalog_success(mock_bundles, invoke, geom_geojson): """Request-catalog command succeeds""" source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", diff --git a/tests/unit/test_subscription_request.py b/tests/unit/test_subscription_request.py index 2cac3851..94f1c02c 100644 --- a/tests/unit/test_subscription_request.py +++ b/tests/unit/test_subscription_request.py @@ -242,7 +242,6 @@ def test_catalog_source_success(geom_geojson, mock_bundles): ) expected = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -270,7 +269,6 @@ def test_catalog_source_featurecollection(featurecollection_geojson, ) expected = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", From 39812b363ebc51396e47ca88d7fca5d4f1d05a70 Mon Sep 17 00:00:00 2001 From: asonnenschein Date: Wed, 19 Mar 2025 09:52:44 -0400 Subject: [PATCH 3/6] update more tests --- tests/integration/test_subscriptions_cli.py | 26 ++++++++++++++------- tests/unit/test_subscription_request.py | 13 ++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/integration/test_subscriptions_cli.py b/tests/integration/test_subscriptions_cli.py index ee69521f..20d0c75d 100644 --- a/tests/integration/test_subscriptions_cli.py +++ b/tests/integration/test_subscriptions_cli.py @@ -306,7 +306,6 @@ def test_subscriptions_results_success(invoke, options, expected_count): def test_request_base_success(invoke, geom_geojson): """Request command succeeds.""" source = json.dumps({ - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -344,7 +343,6 @@ def test_request_base_clip_to_source(geom_fixture, request, invoke): """Clip to source using command line option.""" geom = request.getfixturevalue(geom_fixture) source = json.dumps({ - "type": "catalog", "parameters": { "geometry": geom, "start_time": "2021-03-01T00:00:00Z", @@ -398,23 +396,34 @@ def test_subscriptions_results_csv(invoke): @pytest.mark.parametrize( - "geom", ["geom_geojson", "geom_reference", "str_geom_reference"]) -def test_request_pv_success(invoke, geom, request): + "geom, source_type", [ + ("geom_geojson", "biomass_proxy"), + ("geom_reference", None), + ("str_geom_reference", None) + ]) +def test_request_pv_success(invoke, geom, source_type, request): """Request-pv command succeeds""" geom = request.getfixturevalue(geom) if isinstance(geom, dict): geom = json.dumps(geom) - result = invoke([ + cmd = [ "request-pv", - "--var-type=biomass_proxy", "--var-id=BIOMASS-PROXY_V3.0_10", f"--geometry={geom}", "--start-time=2021-03-01T00:00:00", - ]) + ] + + if source_type: + cmd.append(f"--var-type={source_type}") + + result = invoke(cmd) assert result.exit_code == 0 # success. source = json.loads(result.output) - assert source["type"] == "biomass_proxy" + if source_type is None: + assert "type" not in source + else: + assert source["type"] == "biomass_proxy" assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10" @@ -487,7 +496,6 @@ def test_request_hosting(invoke, expected_success): """Test request command with various hosting and collection ID options.""" source = json.dumps({ - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", diff --git a/tests/unit/test_subscription_request.py b/tests/unit/test_subscription_request.py index 94f1c02c..cc16696b 100644 --- a/tests/unit/test_subscription_request.py +++ b/tests/unit/test_subscription_request.py @@ -24,7 +24,6 @@ def test_build_request_success(geom_geojson): source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -69,7 +68,6 @@ def test_build_request_success(geom_geojson): def test_build_request_clip_to_source_success(geom_geojson): """Without a clip tool we can clip to source.""" source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -95,7 +93,6 @@ def test_build_request_clip_to_source_success(geom_geojson): def test_build_request_clip_to_source_failure(geom_geojson): """With a clip tool we can not clip to source.""" source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -121,7 +118,6 @@ def test_build_request_clip_to_source_failure(geom_geojson): def test_build_request_host_sentinel_hub_no_collection(geom_geojson): source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -145,7 +141,6 @@ def test_build_request_host_sentinel_hub_no_collection(geom_geojson): def test_build_request_host_sentinel_hub_with_collection(geom_geojson): source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -174,7 +169,6 @@ def test_build_request_host_sentinel_hub_with_collection(geom_geojson): def test_build_request_host_sentinel_hub_create_configuration(geom_geojson): source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -203,7 +197,6 @@ def test_build_request_host_sentinel_hub_create_configuration(geom_geojson): def test_build_request_host_sentinel_hub_collection_configuration( geom_geojson): source = { - "type": "catalog", "parameters": { "geometry": geom_geojson, "start_time": "2021-03-01T00:00:00Z", @@ -556,6 +549,7 @@ def test_toar_tool_success(): [ ("biomass_proxy", "BIOMASS-PROXY_V3.0_10"), # actual real type and id. ("var1", "VAR1-ABCD"), # nonsense type and id + (None, "BIOMASS-PROXY_V3.0_10"), # None type with valid id ]) def test_pv_source_success(geom_geojson, var_type, var_id): """Configure a planetary variable subscription source.""" @@ -567,7 +561,10 @@ def test_pv_source_success(geom_geojson, var_type, var_id): end_time=datetime(2021, 3, 2), ) - assert source["type"] == var_type + if var_type is None: + assert "type" not in source + else: + assert source["type"] == var_type params = source["parameters"] assert params["id"] == var_id assert params["geometry"] == geom_geojson From 2042cc80addd609cd44daf5abd5f27307b42602c Mon Sep 17 00:00:00 2001 From: asonnenschein Date: Wed, 19 Mar 2025 09:56:14 -0400 Subject: [PATCH 4/6] lint --- tests/integration/test_subscriptions_cli.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/integration/test_subscriptions_cli.py b/tests/integration/test_subscriptions_cli.py index 20d0c75d..b567f284 100644 --- a/tests/integration/test_subscriptions_cli.py +++ b/tests/integration/test_subscriptions_cli.py @@ -395,12 +395,10 @@ def test_subscriptions_results_csv(invoke): assert result.output.splitlines() == ["id,status", "1234-abcd,SUCCESS"] -@pytest.mark.parametrize( - "geom, source_type", [ - ("geom_geojson", "biomass_proxy"), - ("geom_reference", None), - ("str_geom_reference", None) - ]) +@pytest.mark.parametrize("geom, source_type", + [("geom_geojson", "biomass_proxy"), + ("geom_reference", None), + ("str_geom_reference", None)]) def test_request_pv_success(invoke, geom, source_type, request): """Request-pv command succeeds""" geom = request.getfixturevalue(geom) From cb7544e5022a450a1ce3a20c5b996d4fa26ff2dd Mon Sep 17 00:00:00 2001 From: asonnenschein Date: Thu, 20 Mar 2025 07:03:43 -0400 Subject: [PATCH 5/6] update var_type type hint --- planet/subscription_request.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/planet/subscription_request.py b/planet/subscription_request.py index 71c36a8d..ed2ec166 100644 --- a/planet/subscription_request.py +++ b/planet/subscription_request.py @@ -285,7 +285,7 @@ def catalog_source( def planetary_variable_source( - var_type: str, + var_type: Optional[str], var_id: str, geometry: Union[dict, str], start_time: datetime, @@ -305,7 +305,8 @@ def planetary_variable_source( Parameters: var_type: Planetary Variable type. See documentation for all - available types. + available types. Used to be a required parameter but + is now optional and can be 'None'. var_id: A Planetary Variable ID. See documenation for all available IDs. geometry: The area of interest of the subscription that will be From ccf2bb6d67d3262e44347a1cf64b84b6977fb293 Mon Sep 17 00:00:00 2001 From: asonnenschein Date: Thu, 20 Mar 2025 09:21:25 -0400 Subject: [PATCH 6/6] update docs and standardize none checks --- docs/cli/cli-subscriptions.md | 2 -- tests/integration/test_subscriptions_cli.py | 6 +++--- tests/unit/test_subscription_request.py | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/cli/cli-subscriptions.md b/docs/cli/cli-subscriptions.md index 4147d1df..c84e6a9f 100644 --- a/docs/cli/cli-subscriptions.md +++ b/docs/cli/cli-subscriptions.md @@ -21,7 +21,6 @@ Since there is no UI to easily create subscriptions we’ll start with making a { "name": "First Subscription", "source": { - "type": "catalog", "parameters": { "asset_types": [ "ortho_analytic_8b" @@ -421,7 +420,6 @@ for details. To constrain data delivery by space and time, you will use the ```sh planet subscriptions request-pv \ - --var-type biomass_proxy \ --var-id BIOMASS-PROXY_V3.0_10 \ --geometry geometry.geojson \ --start-time 2022-08-24T00:00:00-07:00 > request-pv.json diff --git a/tests/integration/test_subscriptions_cli.py b/tests/integration/test_subscriptions_cli.py index b567f284..dcdaf293 100644 --- a/tests/integration/test_subscriptions_cli.py +++ b/tests/integration/test_subscriptions_cli.py @@ -418,10 +418,10 @@ def test_request_pv_success(invoke, geom, source_type, request): assert result.exit_code == 0 # success. source = json.loads(result.output) - if source_type is None: - assert "type" not in source - else: + if source_type: assert source["type"] == "biomass_proxy" + else: + assert "type" not in source assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10" diff --git a/tests/unit/test_subscription_request.py b/tests/unit/test_subscription_request.py index cc16696b..0b111c0d 100644 --- a/tests/unit/test_subscription_request.py +++ b/tests/unit/test_subscription_request.py @@ -561,10 +561,10 @@ def test_pv_source_success(geom_geojson, var_type, var_id): end_time=datetime(2021, 3, 2), ) - if var_type is None: - assert "type" not in source - else: + if var_type: assert source["type"] == var_type + else: + assert "type" not in source params = source["parameters"] assert params["id"] == var_id assert params["geometry"] == geom_geojson