Skip to content

Commit

Permalink
Merge pull request #179 from ecmwf-projects/fix-free-edition-widget-l…
Browse files Browse the repository at this point in the history
…abels

Refactor extract_labels function to handle missing "labels" key
  • Loading branch information
mcucchi9 authored Mar 7, 2024
2 parents 7376895 + 06e3d03 commit 09818b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cads_processing_api_service/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def extract_groups_labels(


def extract_labels(input_cds_schema: dict[str, Any]) -> dict[str, str]:
details = input_cds_schema["details"]
details: dict[str, Any] = input_cds_schema["details"]
if "groups" in details:
values = extract_groups_labels(details["groups"])
else:
values = details["labels"]
values = details.get("labels", {})
return values


Expand Down
11 changes: 11 additions & 0 deletions tests/test_10_translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
},
"type": "StringListArrayWidget",
},
"free_edition_widget": {
"type": "FreeEditionWidget",
"details": {},
},
}


Expand Down Expand Up @@ -116,6 +120,13 @@ def test_extract_labels() -> None:
)
assert res_output == exp_output

test_inputs_cds_schema = TEST_INPUT_CDS_SCHEMAS["free_edition_widget"]
exp_output = {}
res_output = cads_processing_api_service.translators.extract_labels(
test_inputs_cds_schema
)
assert res_output == exp_output


def test_translate_string_list() -> None:
test_input = TEST_INPUT_CDS_SCHEMAS["string_list"]
Expand Down

0 comments on commit 09818b7

Please sign in to comment.