Skip to content

Commit 09818b7

Browse files
authored
Merge pull request #179 from ecmwf-projects/fix-free-edition-widget-labels
Refactor extract_labels function to handle missing "labels" key
2 parents 7376895 + 06e3d03 commit 09818b7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cads_processing_api_service/translators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def extract_groups_labels(
3535

3636

3737
def extract_labels(input_cds_schema: dict[str, Any]) -> dict[str, str]:
38-
details = input_cds_schema["details"]
38+
details: dict[str, Any] = input_cds_schema["details"]
3939
if "groups" in details:
4040
values = extract_groups_labels(details["groups"])
4141
else:
42-
values = details["labels"]
42+
values = details.get("labels", {})
4343
return values
4444

4545

tests/test_10_translators.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
},
6161
"type": "StringListArrayWidget",
6262
},
63+
"free_edition_widget": {
64+
"type": "FreeEditionWidget",
65+
"details": {},
66+
},
6367
}
6468

6569

@@ -116,6 +120,13 @@ def test_extract_labels() -> None:
116120
)
117121
assert res_output == exp_output
118122

123+
test_inputs_cds_schema = TEST_INPUT_CDS_SCHEMAS["free_edition_widget"]
124+
exp_output = {}
125+
res_output = cads_processing_api_service.translators.extract_labels(
126+
test_inputs_cds_schema
127+
)
128+
assert res_output == exp_output
129+
119130

120131
def test_translate_string_list() -> None:
121132
test_input = TEST_INPUT_CDS_SCHEMAS["string_list"]

0 commit comments

Comments
 (0)