Skip to content

Commit d8c3b8a

Browse files
Fix issue loading Type using LinodeClient.load(...) (#365)
1 parent b56ee0e commit d8c3b8a

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

linode_api4/objects/linode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,10 @@ def _populate(self, json):
256256
"""
257257
Allows changing the name "class" in JSON to "type_class" in python
258258
"""
259+
259260
super()._populate(json)
260261

261-
if "class" in json:
262+
if json is not None and "class" in json:
262263
setattr(self, "type_class", json["class"])
263264
else:
264265
setattr(self, "type_class", None)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"disk": 20480,
3+
"memory": 1024,
4+
"transfer": 1000,
5+
"addons": {
6+
"backups": {
7+
"price": {
8+
"hourly": 0.003,
9+
"monthly": 2
10+
},
11+
"region_prices": [
12+
{
13+
"id": "ap-west",
14+
"hourly": 0.02,
15+
"monthly": 20
16+
},
17+
{
18+
"id": "ap-northeast",
19+
"hourly": 0.02,
20+
"monthly": 20
21+
}
22+
]
23+
}
24+
},
25+
"class": "nanode",
26+
"network_out": 1000,
27+
"vcpus": 1,
28+
"gpus": 0,
29+
"id": "g5-nanode-1",
30+
"label": "Linode 1024",
31+
"price": {
32+
"hourly": 0.0075,
33+
"monthly": 5
34+
},
35+
"region_prices": [
36+
{
37+
"id": "us-east",
38+
"hourly": 0.02,
39+
"monthly": 20
40+
},
41+
{
42+
"id": "ap-northeast",
43+
"hourly": 0.02,
44+
"monthly": 20
45+
}
46+
],
47+
"successor": null
48+
}

test/unit/objects/linode_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ def test_get_type_gpu(self):
580580
self.assertEqual(t.gpus, 1)
581581
self.assertEqual(t._populated, True)
582582

583+
def test_load_type(self):
584+
"""
585+
Tests that a type can be loaded using LinodeClient.load(...)
586+
"""
587+
588+
t = self.client.load(Type, "g6-nanode-1")
589+
self.assertEqual(t._populated, True)
590+
self.assertEqual(t.type_class, "nanode")
591+
583592
def test_save_noforce(self):
584593
"""
585594
Tests that a client will only save if changes are detected

0 commit comments

Comments
 (0)