Skip to content

Commit ff6e62d

Browse files
committed
validate file_format in file_format_tool, add raised exceptions to docs
1 parent 43ee719 commit ff6e62d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

planet/api/order_details.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def build_request(
6565
tools: Tools to apply to the products. Order defines
6666
the toolchain order of operatations.
6767
68+
Raises:
69+
planet.specs.SpecificationException: If order_type is not a valid
70+
order type.
6871
'''
6972
details = {
7073
'name': name,
@@ -106,6 +109,11 @@ def product(
106109
fallback_bundle: In case product_bundle not having
107110
all asset types available, which would result in failed
108111
delivery, try a fallback bundle
112+
113+
Raises:
114+
planet.specs.SpecificationException: If bundle or fallback bundle
115+
are not valid bundles or if item_type is not valid for the given
116+
bundle or fallback bundle.
109117
'''
110118
product_bundle = specs.validate_bundle(product_bundle)
111119
item_type = specs.validate_item_type(item_type, product_bundle)
@@ -171,6 +179,9 @@ def delivery(
171179
archive file that is received. Uses the template variables
172180
{{name}} and {{order_id}}. e.g. "{{name}}_{{order_id}}.zip".
173181
cloud_config: Cloud delivery configuration.
182+
183+
Raises:
184+
planet.specs.SpecificationException: If archive_type is not valid.
174185
'''
175186
if archive_type:
176187
archive_type = specs.validate_archive_type(archive_type)
@@ -302,6 +313,10 @@ def _tool(name: str, parameters: dict) -> dict:
302313
Parameters:
303314
name: Tool name.
304315
parameters: Tool parameters.
316+
317+
Raises:
318+
planet.specs.SpecificationException: If name is not the name of a valid
319+
Orders API tool.
305320
'''
306321
name = specs.validate_tool(name)
307322
return {name: parameters}
@@ -356,7 +371,12 @@ def file_format_tool(file_format: str) -> dict:
356371
357372
Parameters:
358373
file_format: The format of the tool output. Either 'COG' or 'PL_NITF'.
374+
375+
Raises:
376+
planet.specs.SpecificationException: If file_format is not one of
377+
'COG' or 'PL_NITF'
359378
'''
379+
file_format = specs.validate_file_format(file_format)
360380
return _tool('file_format', {'format': file_format})
361381

362382

planet/specs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'file_format', 'reproject', 'tile', 'toar', 'harmonize']
2525
SUPPORTED_ORDER_TYPES = ['full', 'partial']
2626
SUPPORTED_ARCHIVE_TYPES = ['zip']
27+
SUPPORTED_FILE_FORMATS = ['COG', 'PL_NITF']
2728

2829
LOGGER = logging.getLogger(__name__)
2930

@@ -58,6 +59,10 @@ def validate_tool(tool):
5859
return _validate_field(tool, SUPPORTED_TOOLS, 'tool')
5960

6061

62+
def validate_file_format(file_format):
63+
return _validate_field(file_format, SUPPORTED_FILE_FORMATS, 'file_format')
64+
65+
6166
def _validate_field(value, supported, field_name=None):
6267
try:
6368
value = get_match(value, supported)

tests/unit/test_specs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ def test_validate_arhive_type():
6767
specs.validate_archive_type('notsupported')
6868

6969

70+
def test_validate_file_format():
71+
assert 'COG' == specs.validate_file_format('cog')
72+
73+
with pytest.raises(specs.SpecificationException):
74+
specs.validate_archive_type('notsupported')
75+
76+
7077
def test_get_product_bundles():
7178
bundles = specs.get_product_bundles()
7279
assert TEST_PRODUCT_BUNDLE in bundles

0 commit comments

Comments
 (0)