diff --git a/test/unit/objects/mapped_object_test.py b/test/unit/objects/mapped_object_test.py index 2d83008a..aee01925 100644 --- a/test/unit/objects/mapped_object_test.py +++ b/test/unit/objects/mapped_object_test.py @@ -1,6 +1,7 @@ +from dataclasses import dataclass from test.unit.base import ClientBaseCase -from linode_api4.objects import Base, MappedObject, Property +from linode_api4.objects import Base, JSONObject, MappedObject, Property class MappedObjectCase(ClientBaseCase): @@ -20,7 +21,7 @@ def test_mapped_object_dict(self): mapped_obj = MappedObject(**test_dict) self.assertEqual(mapped_obj.dict, test_dict) - def test_mapped_object_dict(self): + def test_base_objects_serialize(self): test_property_name = "bar" test_property_value = "bar" @@ -42,3 +43,22 @@ class Foo(Base): mapped_obj = MappedObject(foo=foo) self.assertEqual(mapped_obj.dict, expected_dict) + + def test_json_objects_serialize(self): + test_property_name = "bar" + test_property_value = "bar" + + @dataclass + class Foo(JSONObject): + bar: str = "" + + foo = Foo.from_json({test_property_name: test_property_value}) + + expected_dict = { + "foo": { + test_property_name: test_property_value, + } + } + + mapped_obj = MappedObject(foo=foo) + self.assertEqual(mapped_obj.dict, expected_dict)