Skip to content

Commit 5c8f0b9

Browse files
authored
Merge pull request #31 from nansencenter/syntool_converter_options
Pass syntool-converter options
2 parents 671255b + e4b8d2d commit 5c8f0b9

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

geospaas_rest_api/processing_api/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def get_signature(cls, parameters):
141141
tasks_core.unarchive.signature(),
142142
tasks_core.crop.signature(
143143
kwargs={'bounding_box': parameters.get('bounding_box', None)}),
144-
tasks_syntool.convert.signature(),
144+
tasks_syntool.convert.signature(
145+
kwargs={'converter_options': parameters.get('converter_options', None)}),
145146
tasks_syntool.db_insert.signature(),
146147
tasks_core.remove_downloaded.signature())
147148
if parameters.pop('skip_check', False):
@@ -159,7 +160,7 @@ def check_parameters(parameters):
159160
- bounding_box: 4-elements list
160161
- format: value in ['idf']
161162
"""
162-
accepted_keys = ('dataset_id', 'format', 'bounding_box', 'skip_check')
163+
accepted_keys = ('dataset_id', 'format', 'bounding_box', 'skip_check', 'converter_options')
163164
if not set(parameters).issubset(set(accepted_keys)):
164165
raise ValidationError(
165166
f"The convert action accepts only these parameters: {', '.join(accepted_keys)}")
@@ -178,6 +179,10 @@ def check_parameters(parameters):
178179
raise ValidationError("'bounding_box' must be a sequence in the following format: "
179180
"west, north, east, south")
180181

182+
if ('converter_options' in parameters and
183+
not isinstance(parameters['converter_options'], dict)):
184+
raise ValidationError("'converter_options' should be a dictionary")
185+
181186
return parameters
182187

183188
@staticmethod

geospaas_rest_api/tests/test_processing_api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def test_check_parameters_wrong_key(self):
273273
self.assertListEqual(
274274
raised.exception.detail,
275275
[ErrorDetail(string="The convert action accepts only these parameters: "
276-
"dataset_id, format, bounding_box, skip_check",
276+
"dataset_id, format, bounding_box, skip_check, converter_options",
277277
code='invalid')])
278278

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

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

321+
def test_check_parameters_wrong_converter_options_type(self):
322+
"""`check_parameters()` must raise an exception if the
323+
'converter_options' value is of the wrong type
324+
"""
325+
with self.assertRaises(ValidationError):
326+
models.ConvertJob.check_parameters(
327+
{'dataset_id': 1, 'format': 'idf', 'converter_options': '2'})
328+
321329
def test_get_signature_syntool(self):
322330
"""Test the right signature is returned"""
323331
self.maxDiff = None
@@ -326,7 +334,7 @@ def test_get_signature_syntool(self):
326334
tasks_core.unarchive.signature(),
327335
tasks_core.crop.signature(
328336
kwargs={'bounding_box': [0, 20, 20, 0]}),
329-
tasks_syntool.convert.signature(),
337+
tasks_syntool.convert.signature(kwargs={'converter_options': None}),
330338
tasks_syntool.db_insert.signature(),
331339
tasks_core.remove_downloaded.signature())
332340

0 commit comments

Comments
 (0)