2020
2121TEST_INPUT_CDS_SCHEMAS : dict [str , Any ] = {
2222 "string_list" : {
23+ "name" : "string_list" ,
24+ "label" : "String List" ,
2325 "details" : {"labels" : {"val1" : "Val1" , "val2" : "Val2" , "val3" : "Val3" }},
2426 "type" : "StringListWidget" ,
2527 },
2628 "string_list_array" : {
29+ "name" : "string_list_array" ,
30+ "label" : "String List Array" ,
2731 "details" : {
2832 "groups" : [
2933 {"labels" : {"val1" : "Val1" , "val2" : "Val2" }},
3337 "type" : "StringListArrayWidget" ,
3438 },
3539 "string_choice" : {
40+ "name" : "string_choice" ,
41+ "label" : "String Choice" ,
3642 "details" : {
3743 "labels" : {"val1" : "Val1" , "val2" : "Val2" , "val3" : "Val3" },
3844 "default" : "val1" ,
3945 },
4046 "type" : "StringChoiceWidget" ,
4147 },
4248 "geographic_extent_map" : {
49+ "name" : "geographic_extent_map" ,
50+ "label" : "Geographic Extent Map" ,
4351 "details" : {"default" : [1 , 2 , 3 , 4 ]},
4452 "type" : "GeographicExtentMapWidget" ,
4553 },
4654 "geographic_location" : {
55+ "name" : "geographic_location" ,
56+ "label" : "Geographic Location" ,
4757 "details" : {},
4858 "type" : "GeographicLocationWidget" ,
4959 },
5060 "string_list_array_groups" : {
61+ "name" : "string_list_array_groups" ,
62+ "label" : "String List Array Groups" ,
5163 "details" : {
5264 "groups" : [
5365 {
6779 "type" : "StringListArrayWidget" ,
6880 },
6981 "free_edition_widget" : {
82+ "name" : "free_edition_widget" ,
83+ "label" : "Free Edition Widget" ,
7084 "type" : "FreeEditionWidget" ,
7185 "details" : {},
7286 },
87+ "exclusive_group_widget" : {
88+ "name" : "exclusive_group_widget" ,
89+ "label" : "Exclusive Group Widget" ,
90+ "type" : "ExclusiveGroupWidget" ,
91+ "children" : ["child_1" , "child_2" ],
92+ "details" : {"default" : "child_1" },
93+ },
94+ "child_1" : {
95+ "name" : "child_1" ,
96+ "label" : "Child 1" ,
97+ "type" : "Child1Widget" ,
98+ "details" : {},
99+ },
100+ "child_2" : {
101+ "name" : "child_2" ,
102+ "label" : "Child 2" ,
103+ "type" : "Child2Widget" ,
104+ "details" : {},
105+ },
73106}
74107
75108
@@ -143,7 +176,6 @@ def test_translate_string_list() -> None:
143176 res_output = cads_processing_api_service .translators .translate_string_list (
144177 test_input
145178 )
146-
147179 assert res_output == exp_ouput
148180
149181
@@ -156,7 +188,6 @@ def test_translate_string_list_array() -> None:
156188 res_output = cads_processing_api_service .translators .translate_string_list_array (
157189 test_input
158190 )
159-
160191 assert res_output == exp_ouput
161192
162193 test_input = TEST_INPUT_CDS_SCHEMAS ["string_list_array_groups" ]
@@ -170,7 +201,6 @@ def test_translate_string_list_array() -> None:
170201 res_output = cads_processing_api_service .translators .translate_string_list_array (
171202 test_input
172203 )
173-
174204 assert res_output == exp_ouput
175205
176206
@@ -180,7 +210,6 @@ def test_translate_string_choice() -> None:
180210 res_output = cads_processing_api_service .translators .translate_string_choice (
181211 test_input
182212 )
183-
184213 assert res_output == exp_ouput
185214
186215
@@ -198,7 +227,6 @@ def test_translate_geographic_extent_map() -> None:
198227 test_input
199228 )
200229 )
201-
202230 assert res_output == exp_ouput
203231
204232
@@ -236,6 +264,51 @@ def test_make_request_labels() -> None:
236264 assert res_output == exp_output
237265
238266
267+ def test_translate_request_ids_into_labels () -> None :
268+ request = {"key1" : "val1" , "key2" : "val2" }
269+ cds_schema = None
270+ exp_output = {"key1" : "val1" , "key2" : "val2" }
271+ res_output = (
272+ cads_processing_api_service .translators .translate_request_ids_into_labels (
273+ request , cds_schema
274+ )
275+ )
276+ assert res_output == exp_output
277+
278+ request = {
279+ "string_list" : ["val1" , "val2" ],
280+ "string_choice" : "val1" ,
281+ "unknown_key" : "unknown_value" ,
282+ }
283+ cds_schema = [
284+ TEST_INPUT_CDS_SCHEMAS ["string_list" ],
285+ TEST_INPUT_CDS_SCHEMAS ["string_choice" ],
286+ ]
287+ exp_output = {
288+ "String List" : ["Val1" , "Val2" ],
289+ "String Choice" : ["Val1" ],
290+ "unknown_key" : "unknown_value" ,
291+ }
292+ res_output = (
293+ cads_processing_api_service .translators .translate_request_ids_into_labels (
294+ request , cds_schema
295+ )
296+ )
297+ assert res_output == exp_output
298+
299+ request = {}
300+ cds_schema = [
301+ TEST_INPUT_CDS_SCHEMAS ["string_choice" ],
302+ TEST_INPUT_CDS_SCHEMAS ["exclusive_group_widget" ],
303+ TEST_INPUT_CDS_SCHEMAS ["child_1" ],
304+ TEST_INPUT_CDS_SCHEMAS ["child_2" ],
305+ ]
306+ exp_output = {
307+ "String Choice" : ["Val1" ],
308+ "Exclusive Group Widget" : ["Child 1" ],
309+ }
310+
311+
239312def test_format_request_value () -> None :
240313 test_value_1 = "test_value"
241314 exp_output_1 = "'test_value'"
0 commit comments