diff --git a/planet/cli/data.py b/planet/cli/data.py index d138cb517..fdb4279af 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -28,8 +28,8 @@ SEARCH_SORT_DEFAULT, STATS_INTERVAL) -from planet.specs import (get_item_types, - validate_item_type, +from planet.specs import (get_data_item_types, + validate_data_item_type, SpecificationException) from . import types @@ -38,8 +38,8 @@ from .options import limit, pretty from .session import CliSession -ALL_ITEM_TYPES = get_item_types() -valid_item_string = "Valid entries for ITEM_TYPES: " + "|".join(ALL_ITEM_TYPES) +valid_item_string = "Valid entries for ITEM_TYPES: " + "|".join( + get_data_item_types()) @asynccontextmanager @@ -75,7 +75,7 @@ def check_item_types(ctx, param, item_types) -> Optional[List[dict]]: item types.''' try: for item_type in item_types: - validate_item_type(item_type) + validate_data_item_type(item_type) return item_types except SpecificationException as e: raise click.BadParameter(str(e)) @@ -85,7 +85,7 @@ def check_item_type(ctx, param, item_type) -> Optional[List[dict]]: '''Validates the item type provided by comparing it to all supported item types.''' try: - validate_item_type(item_type) + validate_data_item_type(item_type) except SpecificationException as e: raise click.BadParameter(str(e)) diff --git a/planet/clients/data.py b/planet/clients/data.py index 6f8fe0985..7b8133a82 100644 --- a/planet/clients/data.py +++ b/planet/clients/data.py @@ -25,7 +25,7 @@ from ..constants import PLANET_BASE_URL from ..http import Session from ..models import Paged, StreamingBody -from ..specs import validate_item_type +from ..specs import validate_data_item_type BASE_URL = f'{PLANET_BASE_URL}/data/v1/' SEARCHES_PATH = '/searches' @@ -147,7 +147,7 @@ async def search(self, search_filter = search_filter or empty_filter() - item_types = [validate_item_type(item) for item in item_types] + item_types = [validate_data_item_type(item) for item in item_types] request_json = {'filter': search_filter, 'item_types': item_types} if name: request_json['name'] = name @@ -204,7 +204,7 @@ async def create_search(self, """ url = self._searches_url() - item_types = [validate_item_type(item) for item in item_types] + item_types = [validate_data_item_type(item) for item in item_types] request = { 'name': name, 'filter': search_filter, @@ -237,7 +237,7 @@ async def update_search(self, """ url = f'{self._searches_url()}/{search_id}' - item_types = [validate_item_type(item) for item in item_types] + item_types = [validate_data_item_type(item) for item in item_types] request = { 'name': name, 'filter': search_filter, @@ -396,7 +396,7 @@ async def get_stats(self, url = f'{self._base_url}{STATS_PATH}' - item_types = [validate_item_type(item) for item in item_types] + item_types = [validate_data_item_type(item) for item in item_types] request = { 'interval': interval, 'filter': search_filter, @@ -450,7 +450,7 @@ async def get_asset(self, planet.exceptions.ClientError: If asset type identifier is not valid. """ - item_type_id = validate_item_type(item_type_id) + item_type_id = validate_data_item_type(item_type_id) assets = await self.list_item_assets(item_type_id, item_id) try: diff --git a/planet/specs.py b/planet/specs.py index a30a8714b..5e6f59288 100644 --- a/planet/specs.py +++ b/planet/specs.py @@ -70,6 +70,17 @@ def validate_item_type(item_type): return _validate_field(item_type, supported_item_types, 'item_type') +def validate_data_item_type(item_type): + '''Validate and correct capitalization of data api item type.''' + return _validate_field(item_type, get_data_item_types(), 'item_type') + + +def get_data_item_types(): + '''Item types supported by the data api.''' + # This is a quick-fix for gh-956, to be superseded by gh-960 + return get_item_types() | {'SkySatVideo'} + + def validate_order_type(order_type): return _validate_field(order_type, SUPPORTED_ORDER_TYPES, 'order_type') diff --git a/tests/unit/test_specs.py b/tests/unit/test_specs.py index 5b5241e35..d3d4d13ab 100644 --- a/tests/unit/test_specs.py +++ b/tests/unit/test_specs.py @@ -103,6 +103,11 @@ def test_validate_item_type_notsupported_itemtype(): specs.validate_item_type('notsupported') +def test_validate_data_item_type(): + '''ensure skysatvideo is included''' + specs.validate_data_item_type('skysatvideo') + + def test_validate_order_type_supported(): assert 'full' == specs.validate_order_type('FULL')