Debian Codegraph @

tests/utils/test_serialization.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 from typing import Any, List
4
5 from .assets.models import ObjectWithOptionalFieldParams, ShapeParams
6
7 from auth0.management.core.serialization import convert_and_respect_annotation_metadata
8
9 UNION_TEST: ShapeParams = {"radius_measurement": 1.0, "shape_type": "circle", "id": "1"}
10 UNION_TEST_CONVERTED = {"shapeType": "circle", "radiusMeasurement": 1.0, "id": "1"}
11
12
13 def test_convert_and_respect_annotation_metadata() -> None:
14 data: ObjectWithOptionalFieldParams = {
15 "string": "string",
16 "long_": 12345,
17 "bool_": True,
18 "literal": "lit_one",
19 "any": "any",
20 }
21 converted = convert_and_respect_annotation_metadata(
22 object_=data, annotation=ObjectWithOptionalFieldParams, direction="write"
23 )
24 assert converted == {"string": "string", "long": 12345, "bool": True, "literal": "lit_one", "any": "any"}
25
26
27 def test_convert_and_respect_annotation_metadata_in_list() -> None:
28 data: List[ObjectWithOptionalFieldParams] = [
29 {"string": "string", "long_": 12345, "bool_": True, "literal": "lit_one", "any": "any"},
30 {"string": "another string", "long_": 67890, "list_": [], "literal": "lit_one", "any": "any"},
31 ]
32 converted = convert_and_respect_annotation_metadata(
33 object_=data, annotation=List[ObjectWithOptionalFieldParams], direction="write"
34 )
35
36 assert converted == [
37 {"string": "string", "long": 12345, "bool": True, "literal": "lit_one", "any": "any"},
38 {"string": "another string", "long": 67890, "list": [], "literal": "lit_one", "any": "any"},
39 ]
40
41
42 def test_convert_and_respect_annotation_metadata_in_nested_object() -> None:
43 data: ObjectWithOptionalFieldParams = {
44 "string": "string",
45 "long_": 12345,
46 "union": UNION_TEST,
47 "literal": "lit_one",
48 "any": "any",
49 }
50 converted = convert_and_respect_annotation_metadata(
51 object_=data, annotation=ObjectWithOptionalFieldParams, direction="write"
52 )
53
54 assert converted == {
55 "string": "string",
56 "long": 12345,
57 "union": UNION_TEST_CONVERTED,
58 "literal": "lit_one",
59 "any": "any",
60 }
61
62
63 def test_convert_and_respect_annotation_metadata_in_union() -> None:
64 converted = convert_and_respect_annotation_metadata(object_=UNION_TEST, annotation=ShapeParams, direction="write")
65
66 assert converted == UNION_TEST_CONVERTED
67
68
69 def test_convert_and_respect_annotation_metadata_with_empty_object() -> None:
70 data: Any = {}
71 converted = convert_and_respect_annotation_metadata(object_=data, annotation=ShapeParams, direction="write")
72 assert converted == data