Skip to content

Commit

Permalink
Merge pull request #31 from nansencenter/syntool_converter_options
Browse files Browse the repository at this point in the history
Pass syntool-converter options
  • Loading branch information
aperrin66 authored Aug 29, 2024
2 parents 671255b + e4b8d2d commit 5c8f0b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions geospaas_rest_api/processing_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def get_signature(cls, parameters):
tasks_core.unarchive.signature(),
tasks_core.crop.signature(
kwargs={'bounding_box': parameters.get('bounding_box', None)}),
tasks_syntool.convert.signature(),
tasks_syntool.convert.signature(
kwargs={'converter_options': parameters.get('converter_options', None)}),
tasks_syntool.db_insert.signature(),
tasks_core.remove_downloaded.signature())
if parameters.pop('skip_check', False):
Expand All @@ -159,7 +160,7 @@ def check_parameters(parameters):
- bounding_box: 4-elements list
- format: value in ['idf']
"""
accepted_keys = ('dataset_id', 'format', 'bounding_box', 'skip_check')
accepted_keys = ('dataset_id', 'format', 'bounding_box', 'skip_check', 'converter_options')
if not set(parameters).issubset(set(accepted_keys)):
raise ValidationError(
f"The convert action accepts only these parameters: {', '.join(accepted_keys)}")
Expand All @@ -178,6 +179,10 @@ def check_parameters(parameters):
raise ValidationError("'bounding_box' must be a sequence in the following format: "
"west, north, east, south")

if ('converter_options' in parameters and
not isinstance(parameters['converter_options'], dict)):
raise ValidationError("'converter_options' should be a dictionary")

return parameters

@staticmethod
Expand Down
14 changes: 11 additions & 3 deletions geospaas_rest_api/tests/test_processing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def test_check_parameters_wrong_key(self):
self.assertListEqual(
raised.exception.detail,
[ErrorDetail(string="The convert action accepts only these parameters: "
"dataset_id, format, bounding_box, skip_check",
"dataset_id, format, bounding_box, skip_check, converter_options",
code='invalid')])

def test_check_parameters_wrong_format(self):
Expand All @@ -292,7 +292,7 @@ def test_check_parameters_extra_param(self):
self.assertListEqual(
raised.exception.detail,
[ErrorDetail(string="The convert action accepts only these parameters: "
"dataset_id, format, bounding_box, skip_check",
"dataset_id, format, bounding_box, skip_check, converter_options",
code='invalid')])

def test_check_parameters_wrong_type_for_dataset_id(self):
Expand All @@ -318,6 +318,14 @@ def test_check_parameters_wrong_bounding_box_type(self):
models.ConvertJob.check_parameters(
{'dataset_id': 1, 'format': 'idf', 'bounding_box': [2]})

def test_check_parameters_wrong_converter_options_type(self):
"""`check_parameters()` must raise an exception if the
'converter_options' value is of the wrong type
"""
with self.assertRaises(ValidationError):
models.ConvertJob.check_parameters(
{'dataset_id': 1, 'format': 'idf', 'converter_options': '2'})

def test_get_signature_syntool(self):
"""Test the right signature is returned"""
self.maxDiff = None
Expand All @@ -326,7 +334,7 @@ def test_get_signature_syntool(self):
tasks_core.unarchive.signature(),
tasks_core.crop.signature(
kwargs={'bounding_box': [0, 20, 20, 0]}),
tasks_syntool.convert.signature(),
tasks_syntool.convert.signature(kwargs={'converter_options': None}),
tasks_syntool.db_insert.signature(),
tasks_core.remove_downloaded.signature())

Expand Down

0 comments on commit 5c8f0b9

Please sign in to comment.