From e95ab066d81cea5fa7c789a57e2ef72544ab5b67 Mon Sep 17 00:00:00 2001 From: Jennifer Reiber Kyle Date: Thu, 18 May 2023 13:13:58 -0700 Subject: [PATCH 1/3] separate data api item type validation from orders, add skysatvideo as valid data api item type --- planet/cli/data.py | 6 +++--- planet/clients/data.py | 12 ++++++------ planet/specs.py | 9 +++++++++ tests/unit/test_specs.py | 5 +++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index d138cb517..8e5fb4a5c 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -29,7 +29,7 @@ STATS_INTERVAL) from planet.specs import (get_item_types, - validate_item_type, + validate_data_item_type, SpecificationException) from . import types @@ -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..5e71793a9 100644 --- a/planet/specs.py +++ b/planet/specs.py @@ -70,6 +70,15 @@ def validate_item_type(item_type): return _validate_field(item_type, supported_item_types, 'item_type') +def validate_data_item_type(item_type): + '''Item types supported by the data api.''' + # This is a quick-fix for gh-956 + # Ideally, data api will provide it's own source + orders_supported_item_types = get_item_types() + supported_item_types = orders_supported_item_types | {'SkySatVideo'} + return _validate_field(item_type, supported_item_types, 'item_type') + + 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') From a5a635a86303a23e48727c5456ad39e71f528e75 Mon Sep 17 00:00:00 2001 From: Jennifer Reiber Kyle Date: Thu, 18 May 2023 13:23:36 -0700 Subject: [PATCH 2/3] add skysatvideo to list of valid item types in data search help --- planet/cli/data.py | 6 +++--- planet/specs.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index 8e5fb4a5c..fdb4279af 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -28,7 +28,7 @@ SEARCH_SORT_DEFAULT, STATS_INTERVAL) -from planet.specs import (get_item_types, +from planet.specs import (get_data_item_types, validate_data_item_type, SpecificationException) @@ -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 diff --git a/planet/specs.py b/planet/specs.py index 5e71793a9..c78b4441d 100644 --- a/planet/specs.py +++ b/planet/specs.py @@ -73,10 +73,14 @@ def validate_item_type(item_type): def validate_data_item_type(item_type): '''Item types supported by the data api.''' # This is a quick-fix for gh-956 - # Ideally, data api will provide it's own source - orders_supported_item_types = get_item_types() - supported_item_types = orders_supported_item_types | {'SkySatVideo'} - return _validate_field(item_type, supported_item_types, 'item_type') + return _validate_field(item_type, get_data_item_types(), 'item_type') + + +def get_data_item_types(): + # This is a quick-fix for gh-956 + orders_item_types = get_item_types() + data_item_types = orders_item_types | {'SkySatVideo'} + return data_item_types def validate_order_type(order_type): From eabe984d1557e4911dc1463daa916b362a3bf7b4 Mon Sep 17 00:00:00 2001 From: Jennifer Reiber Kyle Date: Fri, 19 May 2023 12:45:25 -0700 Subject: [PATCH 3/3] minimize lines of code, update docstrings, add reference to long term fix gh ticket --- planet/specs.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/planet/specs.py b/planet/specs.py index c78b4441d..5e6f59288 100644 --- a/planet/specs.py +++ b/planet/specs.py @@ -71,16 +71,14 @@ def validate_item_type(item_type): def validate_data_item_type(item_type): - '''Item types supported by the data api.''' - # This is a quick-fix for gh-956 + '''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(): - # This is a quick-fix for gh-956 - orders_item_types = get_item_types() - data_item_types = orders_item_types | {'SkySatVideo'} - return 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):