Skip to content

Commit 9b0d360

Browse files
Merge pull request #331 from linode/proj/dc-specific-pricing
project: DC-Specific Pricing
2 parents 9915f6d + a9915d4 commit 9b0d360

File tree

8 files changed

+174
-11
lines changed

8 files changed

+174
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ release: build
2828
twine upload dist/*
2929

3030
@PHONEY: install
31-
install: clean
31+
install: clean requirements
3232
python3 -m pip install .
3333

3434
@PHONEY: requirements

linode_api4/objects/linode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class Type(Base):
232232
"label": Property(),
233233
"network_out": Property(),
234234
"price": Property(),
235+
"region_prices": Property(),
235236
"addons": Property(),
236237
"memory": Property(),
237238
"transfer": Property(),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"quota": 471,
3+
"used": 737373,
4+
"billable": 0,
5+
6+
"region_transfers": [
7+
{
8+
"id": "ap-west",
9+
"used": 1,
10+
"quota": 5010,
11+
"billable": 0
12+
}
13+
]
14+
}

test/fixtures/linode_types.json

Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"results": 4,
3-
"pages": 1,
4-
"page": 1,
5-
"data": [
2+
"results": 4,
3+
"pages": 1,
4+
"page": 1,
5+
"data": [
66
{
77
"disk": 20480,
88
"memory": 1024,
@@ -12,7 +12,19 @@
1212
"price": {
1313
"hourly": 0.003,
1414
"monthly": 2
15-
}
15+
},
16+
"region_prices": [
17+
{
18+
"id": "ap-west",
19+
"hourly": 0.02,
20+
"monthly": 20
21+
},
22+
{
23+
"id": "ap-northeast",
24+
"hourly": 0.02,
25+
"monthly": 20
26+
}
27+
]
1628
}
1729
},
1830
"class": "nanode",
@@ -25,6 +37,18 @@
2537
"hourly": 0.0075,
2638
"monthly": 5
2739
},
40+
"region_prices": [
41+
{
42+
"id": "us-east",
43+
"hourly": 0.02,
44+
"monthly": 20
45+
},
46+
{
47+
"id": "ap-northeast",
48+
"hourly": 0.02,
49+
"monthly": 20
50+
}
51+
],
2852
"successor": null
2953
},
3054
{
@@ -36,7 +60,19 @@
3660
"price": {
3761
"hourly": 0.008,
3862
"monthly": 5
39-
}
63+
},
64+
"region_prices": [
65+
{
66+
"id": "ap-west",
67+
"hourly": 0.02,
68+
"monthly": 20
69+
},
70+
{
71+
"id": "ap-northeast",
72+
"hourly": 0.02,
73+
"monthly": 20
74+
}
75+
]
4076
}
4177
},
4278
"class": "highmem",
@@ -49,6 +85,18 @@
4985
"hourly": 0.09,
5086
"monthly": 60
5187
},
88+
"region_prices": [
89+
{
90+
"id": "us-east",
91+
"hourly": 0.02,
92+
"monthly": 20
93+
},
94+
{
95+
"id": "ap-northeast",
96+
"hourly": 0.02,
97+
"monthly": 20
98+
}
99+
],
52100
"successor": null
53101
},
54102
{
@@ -60,7 +108,19 @@
60108
"price": {
61109
"hourly": 0.004,
62110
"monthly": 2.5
63-
}
111+
},
112+
"region_prices": [
113+
{
114+
"id": "ap-west",
115+
"hourly": 0.02,
116+
"monthly": 20
117+
},
118+
{
119+
"id": "ap-northeast",
120+
"hourly": 0.02,
121+
"monthly": 20
122+
}
123+
]
64124
}
65125
},
66126
"class": "standard",
@@ -73,6 +133,18 @@
73133
"hourly": 0.015,
74134
"monthly": 10
75135
},
136+
"region_prices": [
137+
{
138+
"id": "us-east",
139+
"hourly": 0.02,
140+
"monthly": 20
141+
},
142+
{
143+
"id": "ap-northeast",
144+
"hourly": 0.02,
145+
"monthly": 20
146+
}
147+
],
76148
"successor": null
77149
},
78150
{
@@ -84,7 +156,19 @@
84156
"price": {
85157
"hourly": 0.008,
86158
"monthly": 5
87-
}
159+
},
160+
"region_prices": [
161+
{
162+
"id": "ap-west",
163+
"hourly": 0.02,
164+
"monthly": 20
165+
},
166+
{
167+
"id": "ap-northeast",
168+
"hourly": 0.02,
169+
"monthly": 20
170+
}
171+
]
88172
}
89173
},
90174
"class": "gpu",
@@ -97,7 +181,19 @@
97181
"hourly": 0.03,
98182
"monthly": 20
99183
},
184+
"region_prices": [
185+
{
186+
"id": "us-east",
187+
"hourly": 0.02,
188+
"monthly": 20
189+
},
190+
{
191+
"id": "ap-northeast",
192+
"hourly": 0.02,
193+
"monthly": 20
194+
}
195+
],
100196
"successor": null
101197
}
102198
]
103-
}
199+
}

test/integration/conftest.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@
66
from linode_api4.linode_client import LinodeClient
77

88
ENV_TOKEN_NAME = "LINODE_TOKEN"
9+
ENV_API_URL_NAME = "LINODE_API_URL"
10+
ENV_API_CA_NAME = "LINODE_API_CA"
911
RUN_LONG_TESTS = "RUN_LONG_TESTS"
1012

1113

1214
def get_token():
1315
return os.environ.get(ENV_TOKEN_NAME, None)
1416

1517

18+
def get_api_url():
19+
return os.environ.get(ENV_API_URL_NAME, "https://api.linode.com/v4beta")
20+
21+
22+
def get_api_ca_file():
23+
result = os.environ.get(ENV_API_CA_NAME, None)
24+
return result if result != "" else None
25+
26+
1627
def run_long_tests():
1728
return os.environ.get(RUN_LONG_TESTS, None)
1829

@@ -71,7 +82,13 @@ def ssh_key_gen():
7182
@pytest.fixture(scope="session")
7283
def get_client():
7384
token = get_token()
74-
client = LinodeClient(token)
85+
api_url = get_api_url()
86+
api_ca_file = get_api_ca_file()
87+
client = LinodeClient(
88+
token,
89+
base_url=api_url,
90+
ca_path=api_ca_file,
91+
)
7592
return client
7693

7794

test/integration/models/test_linode.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,22 @@ def test_get_linode_types(get_client):
398398
assert "g6-nanode-1" in ids
399399

400400

401+
def test_get_linode_types_overrides(get_client):
402+
types = get_client.linode.types()
403+
404+
target_types = [
405+
v
406+
for v in types
407+
if len(v.region_prices) > 0 and v.region_prices[0].hourly > 0
408+
]
409+
410+
assert len(target_types) > 0
411+
412+
for linode_type in target_types:
413+
assert linode_type.region_prices[0].hourly >= 0
414+
assert linode_type.region_prices[0].monthly >= 0
415+
416+
401417
def test_get_linode_type_by_id(get_client):
402418
pytest.skip(
403419
"Might need Type to match how other object models are behaving e.g. client.load(Type, 123)"

test/unit/linode_client_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,22 @@ def test_join_beta_program(self):
476476
)
477477
self.assertEqual(m.call_url, join_beta_url)
478478

479+
def test_account_transfer(self):
480+
"""
481+
Tests that payments can be retrieved
482+
"""
483+
transfer = self.client.account.transfer()
484+
485+
self.assertEqual(transfer.quota, 471)
486+
self.assertEqual(transfer.used, 737373)
487+
self.assertEqual(transfer.billable, 0)
488+
489+
self.assertEqual(len(transfer.region_transfers), 1)
490+
self.assertEqual(transfer.region_transfers[0].id, "ap-west")
491+
self.assertEqual(transfer.region_transfers[0].used, 1)
492+
self.assertEqual(transfer.region_transfers[0].quota, 5010)
493+
self.assertEqual(transfer.region_transfers[0].billable, 0)
494+
479495

480496
class BetaProgramGroupTest(ClientBaseCase):
481497
"""

test/unit/objects/linode_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ def test_get_types(self):
533533
self.assertIsNotNone(t.type_class)
534534
self.assertIsNotNone(t.gpus)
535535
self.assertIsNone(t.successor)
536+
self.assertIsNotNone(t.region_prices)
537+
self.assertIsNotNone(t.addons.backups.region_prices)
536538

537539
def test_get_type_by_id(self):
538540
"""
@@ -546,6 +548,7 @@ def test_get_type_by_id(self):
546548
self.assertEqual(t.label, "Linode 1024")
547549
self.assertEqual(t.disk, 20480)
548550
self.assertEqual(t.type_class, "nanode")
551+
self.assertEqual(t.region_prices[0].id, "us-east")
549552

550553
def test_get_type_gpu(self):
551554
"""

0 commit comments

Comments
 (0)