File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,9 +109,15 @@ def dict(self):
109109 result [k ] = v .dict
110110 elif isinstance (v , list ):
111111 result [k ] = [
112- item .dict if isinstance (item , cls ) else item for item in v
112+ (
113+ item .dict
114+ if isinstance (item , cls )
115+ else item ._raw_json if isinstance (item , Base ) else item
116+ )
117+ for item in v
113118 ]
114-
119+ elif isinstance (v , Base ):
120+ result [k ] = v ._raw_json
115121 return result
116122
117123
Original file line number Diff line number Diff line change 1+ {
2+ "bar" : " bar"
3+ }
Original file line number Diff line number Diff line change 1- from unittest import TestCase
1+ from test . unit . base import ClientBaseCase
22
3- from linode_api4 import MappedObject
3+ from linode_api4 . objects import Base , MappedObject , Property
44
55
6- class MappedObjectCase (TestCase ):
6+ class MappedObjectCase (ClientBaseCase ):
77 def test_mapped_object_dict (self ):
88 test_dict = {
99 "key1" : 1 ,
@@ -19,3 +19,26 @@ def test_mapped_object_dict(self):
1919
2020 mapped_obj = MappedObject (** test_dict )
2121 self .assertEqual (mapped_obj .dict , test_dict )
22+
23+ def test_mapped_object_dict (self ):
24+ test_property_name = "bar"
25+ test_property_value = "bar"
26+
27+ class Foo (Base ):
28+ api_endpoint = "/testmappedobj1"
29+ id_attribute = test_property_name
30+ properties = {
31+ test_property_name : Property (mutable = True ),
32+ }
33+
34+ foo = Foo (self .client , test_property_value )
35+ foo ._api_get ()
36+
37+ expected_dict = {
38+ "foo" : {
39+ test_property_name : test_property_value ,
40+ }
41+ }
42+
43+ mapped_obj = MappedObject (foo = foo )
44+ self .assertEqual (mapped_obj .dict , expected_dict )
You can’t perform that action at this time.
0 commit comments