Skip to content

Commit f952baa

Browse files
authored
Merge pull request #232 from ecmwf-projects/COPDS-2318-fix-processes-response
Fix get processes bugs
2 parents b043ee9 + 40d4a6a commit f952baa

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

cads_processing_api_service/translators.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,29 @@ def translate_string_list_array(
7171

7272
def translate_string_choice(input_cds_schema: dict[str, Any]) -> dict[str, Any]:
7373
labels = extract_labels(input_cds_schema)
74+
default = input_cds_schema["details"].get("default", None)
75+
if type(default) is not str:
76+
if type(default) is list:
77+
default = default[0]
7478
input_ogc_schema = {
7579
"type": "string",
7680
"enum": list(labels.keys()),
77-
"default": input_cds_schema["details"].get("default", None),
81+
"default": default,
7882
}
7983
return input_ogc_schema
8084

8185

8286
def translate_geographic_extent_map(input_cds_schema: dict[str, Any]) -> dict[str, Any]:
87+
default = input_cds_schema["details"].get("default", None)
88+
if type(default) is not list:
89+
if type(default) is dict and "e" in default:
90+
default = [default["n"], default["w"], default["s"], default["e"]]
8391
input_ogc_schema = {
8492
"type": "array",
8593
"minItems": 4,
8694
"maxItems": 4,
8795
"items": {"type": "number"},
88-
"default": input_cds_schema["details"].get("default", None),
96+
"default": default,
8997
}
9098
return input_ogc_schema
9199

tests/test_10_translators.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,27 @@
4747
},
4848
"type": "StringChoiceWidget",
4949
},
50+
"string_choice_default_list": {
51+
"name": "string_choice",
52+
"label": "String Choice",
53+
"details": {
54+
"labels": {"val1": "Val1", "val2": "Val2", "val3": "Val3"},
55+
"default": ["val1"],
56+
},
57+
"type": "StringChoiceWidget",
58+
},
5059
"geographic_extent_map": {
5160
"name": "geographic_extent_map",
5261
"label": "Geographic Extent Map",
5362
"details": {"default": [1, 2, 3, 4]},
5463
"type": "GeographicExtentMapWidget",
5564
},
65+
"geographic_extent_map_default_dict": {
66+
"name": "geographic_extent_map",
67+
"label": "Geographic Extent Map",
68+
"details": {"default": {"n": 1, "w": 2, "s": 3, "e": 4}},
69+
"type": "GeographicExtentMapWidget",
70+
},
5671
"geographic_location": {
5772
"name": "geographic_location",
5873
"label": "Geographic Location",
@@ -194,6 +209,11 @@ def test_translate_string_choice() -> None:
194209
res_output = translators.translate_string_choice(test_input)
195210
assert res_output == exp_ouput
196211

212+
test_input = TEST_INPUT_CDS_SCHEMAS["string_choice_default_list"]
213+
exp_ouput = {"type": "string", "enum": ["val1", "val2", "val3"], "default": "val1"}
214+
res_output = translators.translate_string_choice(test_input)
215+
assert res_output == exp_ouput
216+
197217

198218
def test_translate_geographic_extent_map() -> None:
199219
test_input = TEST_INPUT_CDS_SCHEMAS["geographic_extent_map"]
@@ -207,6 +227,17 @@ def test_translate_geographic_extent_map() -> None:
207227
res_output = translators.translate_geographic_extent_map(test_input)
208228
assert res_output == exp_ouput
209229

230+
test_input = TEST_INPUT_CDS_SCHEMAS["geographic_extent_map_default_dict"]
231+
exp_ouput = {
232+
"type": "array",
233+
"minItems": 4,
234+
"maxItems": 4,
235+
"items": {"type": "number"},
236+
"default": [1, 2, 3, 4],
237+
}
238+
res_output = translators.translate_geographic_extent_map(test_input)
239+
assert res_output == exp_ouput
240+
210241

211242
def test_make_request_labels() -> None:
212243
test_input_value_ids = ["1", "1", "1", "1"]

0 commit comments

Comments
 (0)