1+ from dataclasses import dataclass
12from test .unit .base import ClientBaseCase
23
3- from linode_api4 .objects import Base , MappedObject , Property
4+ from linode_api4 .objects import Base , JSONObject , MappedObject , Property
45
56
67class MappedObjectCase (ClientBaseCase ):
@@ -20,7 +21,7 @@ def test_mapped_object_dict(self):
2021 mapped_obj = MappedObject (** test_dict )
2122 self .assertEqual (mapped_obj .dict , test_dict )
2223
23- def test_mapped_object_dict (self ):
24+ def test_serialize_base_objects (self ):
2425 test_property_name = "bar"
2526 test_property_value = "bar"
2627
@@ -42,3 +43,22 @@ class Foo(Base):
4243
4344 mapped_obj = MappedObject (foo = foo )
4445 self .assertEqual (mapped_obj .dict , expected_dict )
46+
47+ def test_serialize_json_objects (self ):
48+ test_property_name = "bar"
49+ test_property_value = "bar"
50+
51+ @dataclass
52+ class Foo (JSONObject ):
53+ bar : str = ""
54+
55+ foo = Foo .from_json ({test_property_name : test_property_value })
56+
57+ expected_dict = {
58+ "foo" : {
59+ test_property_name : test_property_value ,
60+ }
61+ }
62+
63+ mapped_obj = MappedObject (foo = foo )
64+ self .assertEqual (mapped_obj .dict , expected_dict )
0 commit comments