-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathmapped_object_test.py
More file actions
64 lines (50 loc) · 1.77 KB
/
Copy pathmapped_object_test.py
File metadata and controls
64 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from dataclasses import dataclass
from test.unit.base import ClientBaseCase
from linode_api4.objects import Base, JSONObject, MappedObject, Property
class MappedObjectCase(ClientBaseCase):
def test_mapped_object_dict(self):
test_dict = {
"key1": 1,
"key2": "2",
"key3": 3.3,
"key4": [41, "42", {"key4-3": "43"}],
"key5": {
"key5-1": 1,
"key5-2": {"key5-2-1": {"key5-2-1-1": 1}},
"key5-3": [{"key5-3-1": 531}, {"key5-3-2": 532}],
},
}
mapped_obj = MappedObject(**test_dict)
self.assertEqual(mapped_obj.dict, test_dict)
def test_serialize_base_objects(self):
test_property_name = "bar"
test_property_value = "bar"
class Foo(Base):
api_endpoint = "/testmappedobj1"
id_attribute = test_property_name
properties = {
test_property_name: Property(mutable=True),
}
foo = Foo(self.client, test_property_value)
foo._api_get()
expected_dict = {
"foo": {
test_property_name: test_property_value,
}
}
mapped_obj = MappedObject(foo=foo)
self.assertEqual(mapped_obj.dict, expected_dict)
def test_serialize_json_objects(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)