From a3f5f47d3c105c785cf6e304f260c233fba1e955 Mon Sep 17 00:00:00 2001 From: Adrien Perrin Date: Fri, 26 Jul 2024 13:37:43 +0000 Subject: [PATCH 1/4] support passing options to syntool converter --- geospaas_rest_api/processing_api/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/geospaas_rest_api/processing_api/models.py b/geospaas_rest_api/processing_api/models.py index d35525a..6740986 100644 --- a/geospaas_rest_api/processing_api/models.py +++ b/geospaas_rest_api/processing_api/models.py @@ -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): @@ -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)}") @@ -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_option' in parameters and + not isinstance(parameters['converter_option'], dict)): + raise ValidationError("'converter_option' should be a dictionary") + return parameters @staticmethod From 9c23827a5097a8eef243d49a8c14e2a84f25b1f3 Mon Sep 17 00:00:00 2001 From: Adrien Perrin Date: Mon, 29 Jul 2024 08:08:23 +0000 Subject: [PATCH 2/4] fix tests --- geospaas_rest_api/tests/test_processing_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geospaas_rest_api/tests/test_processing_api.py b/geospaas_rest_api/tests/test_processing_api.py index b60d98a..f762902 100644 --- a/geospaas_rest_api/tests/test_processing_api.py +++ b/geospaas_rest_api/tests/test_processing_api.py @@ -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): @@ -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): @@ -326,7 +326,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()) From 6d24f074d35888466cc48d0401ee1df0fa2fa7df Mon Sep 17 00:00:00 2001 From: Adrien Perrin Date: Mon, 29 Jul 2024 08:16:41 +0000 Subject: [PATCH 3/4] fix typo --- geospaas_rest_api/processing_api/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geospaas_rest_api/processing_api/models.py b/geospaas_rest_api/processing_api/models.py index 6740986..b770bd3 100644 --- a/geospaas_rest_api/processing_api/models.py +++ b/geospaas_rest_api/processing_api/models.py @@ -179,9 +179,9 @@ def check_parameters(parameters): raise ValidationError("'bounding_box' must be a sequence in the following format: " "west, north, east, south") - if ('converter_option' in parameters and - not isinstance(parameters['converter_option'], dict)): - raise ValidationError("'converter_option' should be a dictionary") + if ('converter_options' in parameters and + not isinstance(parameters['converter_options'], dict)): + raise ValidationError("'converter_options' should be a dictionary") return parameters From e4b8d2d1778aa22931f1b2ac58386545c877aa0f Mon Sep 17 00:00:00 2001 From: Adrien Perrin Date: Mon, 29 Jul 2024 08:16:47 +0000 Subject: [PATCH 4/4] add missing test --- geospaas_rest_api/tests/test_processing_api.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/geospaas_rest_api/tests/test_processing_api.py b/geospaas_rest_api/tests/test_processing_api.py index f762902..42f8cdf 100644 --- a/geospaas_rest_api/tests/test_processing_api.py +++ b/geospaas_rest_api/tests/test_processing_api.py @@ -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