Skip to content

Commit fbdddb0

Browse files
committed
update tests to use a mocked bundles spec, clean up linting/formatting
1 parent c30f3c4 commit fbdddb0

File tree

8 files changed

+276
-83
lines changed

8 files changed

+276
-83
lines changed

planet/cli/orders.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@
2727
from .io import echo_json
2828
from .options import limit, pretty
2929
from .session import CliSession
30-
from ..specs import (
31-
FetchBundlesSpecError,
32-
SpecificationException,
33-
validate_bundle,
34-
validate_data_item_type
35-
)
36-
30+
from ..specs import (FetchBundlesSpecError,
31+
SpecificationException,
32+
validate_bundle,
33+
validate_data_item_type)
3734

3835
LOGGER = logging.getLogger(__name__)
3936

@@ -58,7 +55,7 @@ def check_bundle(ctx, param, bundle) -> Optional[List[dict]]:
5855
item_type = ctx.params.get('item_type')
5956
if not item_type:
6057
raise click.BadParameter("Item type is required to validate a bundle.")
61-
58+
6259
try:
6360
validate_bundle(item_type, bundle)
6461
except SpecificationException as e:
@@ -68,6 +65,7 @@ def check_bundle(ctx, param, bundle) -> Optional[List[dict]]:
6865

6966
return bundle
7067

68+
7169
@asynccontextmanager
7270
async def orders_client(ctx):
7371
base_url = ctx.obj['BASE_URL']
@@ -357,9 +355,10 @@ async def create(ctx, request, pretty, **kwargs):
357355
type=types.JSON(),
358356
help="""Clip feature Polygon or Multipolygon GeoJSON. Can be a
359357
json string, filename, or '-' for stdin.""")
360-
@click.option('--tools',
361-
type=types.JSON(),
362-
help="""Toolchain JSON. Can be a json string, filename, or '-' for
358+
@click.option(
359+
'--tools',
360+
type=types.JSON(),
361+
help="""Toolchain JSON. Can be a json string, filename, or '-' for
363362
stdin.""")
364363
@click.option('--email',
365364
default=False,

planet/specs.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
LOGGER = logging.getLogger(__name__)
4040

41+
4142
class FetchBundlesSpecError(Exception):
4243
"""Custom exception for errors fetching the product bundles spec."""
4344
pass
@@ -56,18 +57,22 @@ def __getitem__(self, key):
5657
response = httpx.get(bundles_spec_url)
5758
response.raise_for_status()
5859
break
59-
except:
60+
except: # noqa: E722
6061
if attempt == retries:
61-
raise FetchBundlesSpecError(f"Unable to fetch product bundles spec from API to perform client side validation on item types and product bundles. Please retry!") from None
62+
raise FetchBundlesSpecError(
63+
"Unable to fetch product bundles spec from API to perform client side validation on item types and product bundles. Please retry!"
64+
) from None
6265
bundles = response.json()['bundles']
6366
cache = {
64-
'bundles': bundles,
65-
'bundle_names': bundles.keys(),
66-
'item_types': set(
67+
'bundles':
68+
bundles,
69+
'bundle_names':
70+
bundles.keys(),
71+
'item_types':
72+
set(
6773
itertools.chain.from_iterable(
68-
bundles[bundle]['assets'].keys() for bundle in bundles.keys()
69-
)
70-
)
74+
bundles[bundle]['assets'].keys()
75+
for bundle in bundles.keys()))
7176
}
7277
setattr(self, "cache", cache)
7378
return cache[key]
@@ -97,11 +102,15 @@ def __str__(self):
97102

98103
def validate_bundle(item_type, bundle):
99104
validate_supported_bundles(item_type, bundle)
100-
return _validate_field(bundle, PRODUCT_BUNDLES["bundle_names"], 'product_bundle')
105+
return _validate_field(bundle,
106+
PRODUCT_BUNDLES["bundle_names"],
107+
'product_bundle')
101108

102109

103110
def validate_item_type(item_type):
104-
return _validate_field(item_type, PRODUCT_BUNDLES["item_types"], 'item_type')
111+
return _validate_field(item_type,
112+
PRODUCT_BUNDLES["item_types"],
113+
'item_type')
105114

106115

107116
def validate_data_item_type(item_type):
@@ -119,6 +128,7 @@ def get_bundle_names():
119128
"""Get all product bundle names."""
120129
return PRODUCT_BUNDLES["bundle_names"]
121130

131+
122132
def validate_order_type(order_type):
123133
return _validate_field(order_type, SUPPORTED_ORDER_TYPES, 'order_type')
124134

@@ -152,7 +162,8 @@ def validate_supported_bundles(item_type, bundle):
152162
# get all the supported bundles for the given item type
153163
supported_bundles = []
154164
for product_bundle in PRODUCT_BUNDLES["bundle_names"]:
155-
available_item_types = set(PRODUCT_BUNDLES["bundles"][product_bundle]['assets'].keys())
165+
available_item_types = set(
166+
PRODUCT_BUNDLES["bundles"][product_bundle]['assets'].keys())
156167
if item_type.lower() in [x.lower() for x in available_item_types]:
157168
supported_bundles.append(product_bundle)
158169
# validate the provided bundle is in the list of supported bundles
@@ -187,7 +198,8 @@ def get_product_bundles(item_type=None):
187198
if item_type:
188199
supported_bundles = []
189200
for product_bundle in PRODUCT_BUNDLES["bundle_names"]:
190-
available_item_types = set(PRODUCT_BUNDLES["bundles"][product_bundle]['assets'].keys())
201+
available_item_types = set(
202+
PRODUCT_BUNDLES["bundles"][product_bundle]['assets'].keys())
191203
if item_type.lower() in [x.lower() for x in available_item_types]:
192204
supported_bundles.append(product_bundle)
193205
return supported_bundles

0 commit comments

Comments
 (0)