Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion planet/cli/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions planet/subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 16 additions & 11 deletions tests/integration/test_subscriptions_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -370,7 +368,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",
Expand Down Expand Up @@ -398,24 +395,33 @@ def test_subscriptions_results_csv(invoke):
assert result.output.splitlines() == ["id,status", "1234-abcd,SUCCESS"]


@pytest.mark.parametrize(
"geom", ["geom_geojson", "geom_reference", "str_geom_reference"])
def test_request_pv_success(invoke, geom, request):
@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)
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"


Expand Down Expand Up @@ -488,7 +494,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",
Expand Down
15 changes: 5 additions & 10 deletions tests/unit/test_subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -242,7 +235,6 @@ def test_catalog_source_success(geom_geojson, mock_bundles):
)

expected = {
"type": "catalog",
"parameters": {
"geometry": geom_geojson,
"start_time": "2021-03-01T00:00:00Z",
Expand Down Expand Up @@ -270,7 +262,6 @@ def test_catalog_source_featurecollection(featurecollection_geojson,
)

expected = {
"type": "catalog",
"parameters": {
"geometry": geom_geojson,
"start_time": "2021-03-01T00:00:00Z",
Expand Down Expand Up @@ -558,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."""
Expand All @@ -569,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
Expand Down