Skip to content

Commit 3781d4c

Browse files
Make Subscription Source Type Optional (#1107)
* make subscription source type optional * fix failing tests * update more tests * lint * update var_type type hint * update docs and standardize none checks
1 parent 146ae72 commit 3781d4c

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

docs/cli/cli-subscriptions.md

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Since there is no UI to easily create subscriptions we’ll start with making a
2121
{
2222
"name": "First Subscription",
2323
"source": {
24-
"type": "catalog",
2524
"parameters": {
2625
"asset_types": [
2726
"ortho_analytic_8b"
@@ -421,7 +420,6 @@ for details. To constrain data delivery by space and time, you will use the
421420

422421
```sh
423422
planet subscriptions request-pv \
424-
--var-type biomass_proxy \
425423
--var-id BIOMASS-PROXY_V3.0_10 \
426424
--geometry geometry.geojson \
427425
--start-time 2022-08-24T00:00:00-07:00 > request-pv.json

planet/cli/subscriptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def request_catalog(item_types,
483483
@translate_exceptions
484484
@click.option(
485485
'--var-type',
486-
required=True,
486+
required=False,
487487
help='A Planetary Variable type. See documentation for all available types.'
488488
)
489489
@click.option(

planet/subscription_request.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ def catalog_source(
281281
if time_range_type:
282282
parameters['time_range_type'] = time_range_type
283283

284-
return {"type": "catalog", "parameters": parameters}
284+
return {"parameters": parameters}
285285

286286

287287
def planetary_variable_source(
288-
var_type: str,
288+
var_type: Optional[str],
289289
var_id: str,
290290
geometry: Union[dict, str],
291291
start_time: datetime,
@@ -305,7 +305,8 @@ def planetary_variable_source(
305305
306306
Parameters:
307307
var_type: Planetary Variable type. See documentation for all
308-
available types.
308+
available types. Used to be a required parameter but
309+
is now optional and can be 'None'.
309310
var_id: A Planetary Variable ID. See documenation for all
310311
available IDs.
311312
geometry: The area of interest of the subscription that will be
@@ -369,7 +370,10 @@ def planetary_variable_source(
369370
except AttributeError:
370371
raise ClientError('Could not convert end_time to an iso string')
371372

372-
return {"type": var_type, "parameters": parameters}
373+
source: dict[str, Any] = {"parameters": parameters}
374+
if var_type:
375+
source["type"] = var_type
376+
return source
373377

374378

375379
def _datetime_to_rfc3339(value: datetime) -> str:

tests/integration/test_subscriptions_cli.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def test_subscriptions_results_success(invoke, options, expected_count):
306306
def test_request_base_success(invoke, geom_geojson):
307307
"""Request command succeeds."""
308308
source = json.dumps({
309-
"type": "catalog",
310309
"parameters": {
311310
"geometry": geom_geojson,
312311
"start_time": "2021-03-01T00:00:00Z",
@@ -344,7 +343,6 @@ def test_request_base_clip_to_source(geom_fixture, request, invoke):
344343
"""Clip to source using command line option."""
345344
geom = request.getfixturevalue(geom_fixture)
346345
source = json.dumps({
347-
"type": "catalog",
348346
"parameters": {
349347
"geometry": geom,
350348
"start_time": "2021-03-01T00:00:00Z",
@@ -370,7 +368,6 @@ def test_request_base_clip_to_source(geom_fixture, request, invoke):
370368
def test_request_catalog_success(mock_bundles, invoke, geom_geojson):
371369
"""Request-catalog command succeeds"""
372370
source = {
373-
"type": "catalog",
374371
"parameters": {
375372
"geometry": geom_geojson,
376373
"start_time": "2021-03-01T00:00:00Z",
@@ -398,24 +395,33 @@ def test_subscriptions_results_csv(invoke):
398395
assert result.output.splitlines() == ["id,status", "1234-abcd,SUCCESS"]
399396

400397

401-
@pytest.mark.parametrize(
402-
"geom", ["geom_geojson", "geom_reference", "str_geom_reference"])
403-
def test_request_pv_success(invoke, geom, request):
398+
@pytest.mark.parametrize("geom, source_type",
399+
[("geom_geojson", "biomass_proxy"),
400+
("geom_reference", None),
401+
("str_geom_reference", None)])
402+
def test_request_pv_success(invoke, geom, source_type, request):
404403
"""Request-pv command succeeds"""
405404
geom = request.getfixturevalue(geom)
406405
if isinstance(geom, dict):
407406
geom = json.dumps(geom)
408-
result = invoke([
407+
cmd = [
409408
"request-pv",
410-
"--var-type=biomass_proxy",
411409
"--var-id=BIOMASS-PROXY_V3.0_10",
412410
f"--geometry={geom}",
413411
"--start-time=2021-03-01T00:00:00",
414-
])
412+
]
413+
414+
if source_type:
415+
cmd.append(f"--var-type={source_type}")
416+
417+
result = invoke(cmd)
415418

416419
assert result.exit_code == 0 # success.
417420
source = json.loads(result.output)
418-
assert source["type"] == "biomass_proxy"
421+
if source_type:
422+
assert source["type"] == "biomass_proxy"
423+
else:
424+
assert "type" not in source
419425
assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10"
420426

421427

@@ -488,7 +494,6 @@ def test_request_hosting(invoke,
488494
expected_success):
489495
"""Test request command with various hosting and collection ID options."""
490496
source = json.dumps({
491-
"type": "catalog",
492497
"parameters": {
493498
"geometry": geom_geojson,
494499
"start_time": "2021-03-01T00:00:00Z",

tests/unit/test_subscription_request.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
def test_build_request_success(geom_geojson):
2626
source = {
27-
"type": "catalog",
2827
"parameters": {
2928
"geometry": geom_geojson,
3029
"start_time": "2021-03-01T00:00:00Z",
@@ -69,7 +68,6 @@ def test_build_request_success(geom_geojson):
6968
def test_build_request_clip_to_source_success(geom_geojson):
7069
"""Without a clip tool we can clip to source."""
7170
source = {
72-
"type": "catalog",
7371
"parameters": {
7472
"geometry": geom_geojson,
7573
"start_time": "2021-03-01T00:00:00Z",
@@ -95,7 +93,6 @@ def test_build_request_clip_to_source_success(geom_geojson):
9593
def test_build_request_clip_to_source_failure(geom_geojson):
9694
"""With a clip tool we can not clip to source."""
9795
source = {
98-
"type": "catalog",
9996
"parameters": {
10097
"geometry": geom_geojson,
10198
"start_time": "2021-03-01T00:00:00Z",
@@ -121,7 +118,6 @@ def test_build_request_clip_to_source_failure(geom_geojson):
121118

122119
def test_build_request_host_sentinel_hub_no_collection(geom_geojson):
123120
source = {
124-
"type": "catalog",
125121
"parameters": {
126122
"geometry": geom_geojson,
127123
"start_time": "2021-03-01T00:00:00Z",
@@ -145,7 +141,6 @@ def test_build_request_host_sentinel_hub_no_collection(geom_geojson):
145141

146142
def test_build_request_host_sentinel_hub_with_collection(geom_geojson):
147143
source = {
148-
"type": "catalog",
149144
"parameters": {
150145
"geometry": geom_geojson,
151146
"start_time": "2021-03-01T00:00:00Z",
@@ -174,7 +169,6 @@ def test_build_request_host_sentinel_hub_with_collection(geom_geojson):
174169

175170
def test_build_request_host_sentinel_hub_create_configuration(geom_geojson):
176171
source = {
177-
"type": "catalog",
178172
"parameters": {
179173
"geometry": geom_geojson,
180174
"start_time": "2021-03-01T00:00:00Z",
@@ -203,7 +197,6 @@ def test_build_request_host_sentinel_hub_create_configuration(geom_geojson):
203197
def test_build_request_host_sentinel_hub_collection_configuration(
204198
geom_geojson):
205199
source = {
206-
"type": "catalog",
207200
"parameters": {
208201
"geometry": geom_geojson,
209202
"start_time": "2021-03-01T00:00:00Z",
@@ -242,7 +235,6 @@ def test_catalog_source_success(geom_geojson, mock_bundles):
242235
)
243236

244237
expected = {
245-
"type": "catalog",
246238
"parameters": {
247239
"geometry": geom_geojson,
248240
"start_time": "2021-03-01T00:00:00Z",
@@ -270,7 +262,6 @@ def test_catalog_source_featurecollection(featurecollection_geojson,
270262
)
271263

272264
expected = {
273-
"type": "catalog",
274265
"parameters": {
275266
"geometry": geom_geojson,
276267
"start_time": "2021-03-01T00:00:00Z",
@@ -558,6 +549,7 @@ def test_toar_tool_success():
558549
[
559550
("biomass_proxy", "BIOMASS-PROXY_V3.0_10"), # actual real type and id.
560551
("var1", "VAR1-ABCD"), # nonsense type and id
552+
(None, "BIOMASS-PROXY_V3.0_10"), # None type with valid id
561553
])
562554
def test_pv_source_success(geom_geojson, var_type, var_id):
563555
"""Configure a planetary variable subscription source."""
@@ -569,7 +561,10 @@ def test_pv_source_success(geom_geojson, var_type, var_id):
569561
end_time=datetime(2021, 3, 2),
570562
)
571563

572-
assert source["type"] == var_type
564+
if var_type:
565+
assert source["type"] == var_type
566+
else:
567+
assert "type" not in source
573568
params = source["parameters"]
574569
assert params["id"] == var_id
575570
assert params["geometry"] == geom_geojson

0 commit comments

Comments
 (0)