forked from linode/linode_api4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregion_test.py
More file actions
75 lines (59 loc) · 2.5 KB
/
Copy pathregion_test.py
File metadata and controls
75 lines (59 loc) · 2.5 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
65
66
67
68
69
70
71
72
73
74
75
import json
from test.unit.base import ClientBaseCase
from linode_api4.objects.region import RegionAvailabilityEntry
class RegionTest(ClientBaseCase):
"""
Tests methods of the Region class
"""
def test_list_availability(self):
"""
Tests that region availability can be listed and filtered on.
"""
with self.mock_get("/regions/availability") as m:
avail_entries = self.client.regions.availability(
RegionAvailabilityEntry.filters.region == "us-east",
RegionAvailabilityEntry.filters.plan == "premium4096.7",
)
assert len(avail_entries) > 0
for entry in avail_entries:
assert entry.region is not None
assert len(entry.region) > 0
assert len(entry.plan) > 0
assert entry.available is not None
# Ensure all three pages are read
assert m.call_count == 3
assert m.mock.call_args_list[0].args[0] == "//regions/availability"
assert (
m.mock.call_args_list[1].args[0]
== "//regions/availability?page=2&page_size=100"
)
assert (
m.mock.call_args_list[2].args[0]
== "//regions/availability?page=3&page_size=100"
)
# Ensure the filter headers are correct
for k, call in m.mock.call_args_list:
assert json.loads(call.get("headers").get("X-Filter")) == {
"+and": [{"region": "us-east"}, {"plan": "premium4096.7"}]
}
def test_list_vpc_availability(self):
"""
Tests that region VPC availability can be listed.
"""
with self.mock_get("/regions/vpc-availability") as m:
vpc_entries = self.client.regions.vpc_availability()
assert len(vpc_entries) > 0
for entry in vpc_entries:
assert len(entry.region) > 0
assert entry.available is not None
# available_ipv6_prefix_lengths may be empty list but should exist
assert entry.available_ipv6_prefix_lengths is not None
# Ensure both pages are read
assert m.call_count == 2
assert (
m.mock.call_args_list[0].args[0] == "//regions/vpc-availability"
)
assert (
m.mock.call_args_list[1].args[0]
== "//regions/vpc-availability?page=2&page_size=25"
)