88from pulp_glue .common import oas
99from pulp_glue .common .exceptions import SchemaError , ValidationError
1010from pulp_glue .common .schema import (
11+ encode_html ,
1112 encode_json ,
1213 encode_param ,
14+ encode_stringify ,
1315 validate ,
1416)
1517
@@ -414,10 +416,7 @@ def test_json_encoder_rejects_stream() -> None:
414416
415417@pytest .mark .parametrize (
416418 "value" ,
417- (
418- pytest .param ("asdf" , id = "string" ),
419- pytest .param (42 , id = "integer" ),
420- ),
419+ (pytest .param ("asdf" , id = "string" ),),
421420)
422421def test_encode_param_keeps (value : t .Any ) -> None :
423422 assert encode_param (value ) == value
@@ -426,6 +425,7 @@ def test_encode_param_keeps(value: t.Any) -> None:
426425@pytest .mark .parametrize (
427426 "value,expected" ,
428427 (
428+ pytest .param (42 , "42" , id = "integer" ),
429429 pytest .param (datetime .date (2000 , 1 , 1 ), "2000-01-01" , id = "date" ),
430430 pytest .param (
431431 datetime .datetime (2000 , 1 , 1 , 12 , 30 ), "2000-01-01T12:30:00.000000Z" , id = "datetime"
@@ -434,3 +434,101 @@ def test_encode_param_keeps(value: t.Any) -> None:
434434)
435435def test_encode_param_transforms (value : t .Any , expected : t .Any ) -> None :
436436 assert encode_param (value ) == expected
437+
438+
439+ @pytest .mark .parametrize (
440+ "value,expected" ,
441+ (
442+ pytest .param (
443+ datetime .date (2000 , 1 , 1 ),
444+ {"" : "2000-01-01" },
445+ id = "date" ,
446+ ),
447+ pytest .param (
448+ {"a" : datetime .datetime (2000 , 1 , 1 , 12 , 30 )},
449+ {"a" : "2000-01-01T12:30:00.000000Z" },
450+ id = "datetime" ,
451+ ),
452+ pytest .param (
453+ [1 , 1 , 12 , 30 ],
454+ {"[0]" : "1" , "[1]" : "1" , "[2]" : "12" , "[3]" : "30" },
455+ id = "list" ,
456+ ),
457+ pytest .param (
458+ {"a" : 1 , "b" : 2 },
459+ {"a" : "1" , "b" : "2" },
460+ id = "dict" ,
461+ ),
462+ pytest .param (
463+ {"o" : {"a" : 1 , "b" : 2 }},
464+ {"o.a" : "1" , "o.b" : "2" },
465+ id = "nested_dict" ,
466+ ),
467+ pytest .param (
468+ [{"a" : 1 , "b" : 2 }, {"c" : 3 }],
469+ {"[0]a" : "1" , "[0]b" : "2" , "[1]c" : "3" },
470+ id = "list_of_dicts" ,
471+ ),
472+ pytest .param (
473+ {"a" : [1 , 2 ], "b" : [3 , 4 ]},
474+ {"a[0]" : "1" , "a[1]" : "2" , "b[0]" : "3" , "b[1]" : "4" },
475+ id = "dict_of_lists" ,
476+ ),
477+ ),
478+ )
479+ def test_encode_html (value : t .Any , expected : t .Any ) -> None :
480+ assert encode_html (value ) == expected
481+
482+
483+ @pytest .mark .parametrize (
484+ "value,expected" ,
485+ (
486+ pytest .param (
487+ "Hello, World!" ,
488+ "Hello, World!" ,
489+ id = "string" ,
490+ ),
491+ pytest .param (
492+ 4 ,
493+ "4" ,
494+ id = "integer" ,
495+ ),
496+ pytest .param (
497+ 3.14159 ,
498+ "3.14159" ,
499+ id = "float" ,
500+ ),
501+ pytest .param (
502+ False ,
503+ "false" ,
504+ id = "bool" ,
505+ ),
506+ pytest .param (
507+ datetime .date (2000 , 1 , 1 ),
508+ "2000-01-01" ,
509+ id = "date" ,
510+ ),
511+ pytest .param (
512+ {"a" : datetime .datetime (2000 , 1 , 1 , 12 , 30 )},
513+ '{"a": "2000-01-01T12:30:00.000000Z"}' ,
514+ id = "datetime" ,
515+ ),
516+ pytest .param (
517+ {"a" : 1 , "b" : 2 },
518+ '{"a": 1, "b": 2}' ,
519+ id = "dict" ,
520+ ),
521+ pytest .param (
522+ {"o" : {"a" : 1 , "b" : 2 }},
523+ '{"o": {"a": 1, "b": 2}}' ,
524+ id = "nested_dict" ,
525+ ),
526+ pytest .param (
527+ {"a" : [1 , 2 ], "b" : [3 , 4 ]},
528+ '{"a": [1, 2], "b": [3, 4]}' ,
529+ id = "dict_of_lists" ,
530+ ),
531+ ),
532+ )
533+ def test_encode_stringify (value : t .Any , expected : str ) -> None :
534+ assert encode_stringify (value ) == expected
0 commit comments