Skip to content

Commit 504374c

Browse files
Merge pull request #713 from planetlabs/human_readable_invalid_itemtype_report-reopened-690
Validated item type with specs module
2 parents 3aa0799 + 605e804 commit 504374c

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

planet/cli/data.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
from planet.clients.data import (SEARCH_SORT,
2222
SEARCH_SORT_DEFAULT,
2323
STATS_INTERVAL)
24-
from planet.specs import get_item_types, SpecificationException
24+
from planet.specs import (get_item_types,
25+
validate_item_type,
26+
SpecificationException)
2527

2628
from . import types
2729
from .cmds import coro, translate_exceptions
@@ -65,15 +67,14 @@ def assets_to_filter(ctx, param, assets: List[str]) -> Optional[dict]:
6567

6668

6769
def check_item_types(ctx, param, item_types) -> Optional[List[dict]]:
68-
# Set difference between given item types and all item types
69-
invalid_item_types = set([item.lower() for item in item_types]) - set(
70-
[a.lower() for a in ALL_ITEM_TYPES])
71-
if invalid_item_types:
72-
raise SpecificationException(invalid_item_types,
73-
ALL_ITEM_TYPES,
74-
'item_type')
75-
else:
70+
'''Validates the item type by comparing the inputted item type to all
71+
supported item types.'''
72+
try:
73+
for item_type in item_types:
74+
validate_item_type(item_type)
7675
return item_types
76+
except SpecificationException as e:
77+
raise click.BadParameter(e)
7778

7879

7980
def date_range_to_filter(ctx, param, values) -> Optional[List[dict]]:

tests/integration/test_orders_cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ def test_cli_orders_request_item_type_invalid(invoke):
491491
'--id=4500474_2133707_2021-05-20_2419',
492492
])
493493
assert result.exit_code == 2
494-
assert "Usage: main orders request [OPTIONS] ITEM_TYPE BUNDLE" in result.output
494+
error_msg = "Usage: main orders request [OPTIONS] ITEM_TYPE BUNDLE"
495+
assert error_msg in result.output
495496

496497

497498
def test_cli_orders_request_product_bundle_invalid(invoke):
@@ -503,7 +504,8 @@ def test_cli_orders_request_product_bundle_invalid(invoke):
503504
'--id=4500474_2133707_2021-05-20_2419',
504505
])
505506
assert result.exit_code == 2
506-
assert "Usage: main orders request [OPTIONS] ITEM_TYPE BUNDLE" in result.output
507+
error_msg = "Usage: main orders request [OPTIONS] ITEM_TYPE BUNDLE"
508+
assert error_msg in result.output
507509

508510

509511
def test_cli_orders_request_product_bundle_incompatible(invoke):
@@ -515,7 +517,8 @@ def test_cli_orders_request_product_bundle_incompatible(invoke):
515517
'--id=4500474_2133707_2021-05-20_2419',
516518
])
517519
assert result.exit_code == 2
518-
assert "Usage: main orders request [OPTIONS] ITEM_TYPE BUNDLE" in result.output
520+
error_msg = "Usage: main orders request [OPTIONS] ITEM_TYPE BUNDLE"
521+
assert error_msg in result.output
519522

520523

521524
def test_cli_orders_request_id_empty(invoke):

tests/unit/test_data_callbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
import logging
1515
import pytest
16-
from planet.specs import SpecificationException
16+
import click
1717
from planet.cli.data import check_item_types
1818

1919
LOGGER = logging.getLogger(__name__)
@@ -51,5 +51,5 @@ def test_item_type_success(item_types):
5151

5252
def test_item_type_fail():
5353
ctx = MockContext()
54-
with pytest.raises(SpecificationException):
54+
with pytest.raises(click.BadParameter):
5555
check_item_types(ctx, 'item_type', "bad_item_type")

0 commit comments

Comments
 (0)