-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathvpc_test.py
More file actions
124 lines (99 loc) · 3.74 KB
/
Copy pathvpc_test.py
File metadata and controls
124 lines (99 loc) · 3.74 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import datetime
from test.unit.base import ClientBaseCase
from linode_api4 import DATE_FORMAT, VPC, VPCIPv4DefaultRange, VPCSubnet
class VPCTest(ClientBaseCase):
"""
Tests methods of the VPC Group
"""
def test_create_vpc(self):
"""
Tests that you can create a VPC.
"""
with self.mock_post("/vpcs/123456") as m:
vpc = self.client.vpcs.create("test-vpc", "us-southeast")
self.assertEqual(m.call_url, "/vpcs")
self.assertEqual(
m.call_data,
{
"label": "test-vpc",
"region": "us-southeast",
},
)
self.assertEqual(vpc._populated, True)
self.validate_vpc_123456(vpc)
def test_create_vpc_with_subnet(self):
"""
Tests that you can create a VPC.
"""
with self.mock_post("/vpcs/123456") as m:
vpc = self.client.vpcs.create(
"test-vpc",
"us-southeast",
subnets=[{"label": "test-subnet", "ipv4": "10.0.0.0/24"}],
)
self.assertEqual(m.call_url, "/vpcs")
self.assertEqual(
m.call_data,
{
"label": "test-vpc",
"region": "us-southeast",
"subnets": [
{"label": "test-subnet", "ipv4": "10.0.0.0/24"}
],
},
)
self.assertEqual(vpc._populated, True)
self.validate_vpc_123456(vpc)
def test_list_ips(self):
"""
Validates that all VPC IPs can be listed.
"""
with self.mock_get("/vpcs/ips") as m:
result = self.client.vpcs.ips()
assert m.call_url == "/vpcs/ips"
assert len(result) == 1
ip = result[0]
assert ip.address == "10.0.0.2"
assert ip.address_range is None
assert ip.vpc_id == 123
assert ip.subnet_id == 456
assert ip.region == "us-mia"
assert ip.linode_id == 123
assert ip.config_id == 456
assert ip.interface_id == 789
assert ip.active
assert ip.nat_1_1 == "172.233.179.133"
assert ip.gateway == "10.0.0.1"
assert ip.prefix == 24
assert ip.subnet_mask == "255.255.255.0"
def validate_vpc_123456(self, vpc: VPC):
expected_dt = datetime.datetime.strptime(
"2018-01-01T00:01:01", DATE_FORMAT
)
self.assertEqual(vpc.label, "test-vpc")
self.assertEqual(vpc.description, "A very real VPC.")
self.assertEqual(vpc.region.id, "us-southeast")
self.assertEqual(vpc.created, expected_dt)
self.assertEqual(vpc.updated, expected_dt)
self.assertEqual(vpc.ipv4[0].range, "10.0.0.0/8")
def validate_vpc_subnet_789(self, subnet: VPCSubnet):
expected_dt = datetime.datetime.strptime(
"2018-01-01T00:01:01", DATE_FORMAT
)
self.assertEqual(subnet.label, "test-subnet")
self.assertEqual(subnet.ipv4, "10.0.0.0/24")
self.assertEqual(subnet.linodes[0].id, 12345)
self.assertEqual(subnet.created, expected_dt)
self.assertEqual(subnet.updated, expected_dt)
def test_default_ranges(self):
"""
Tests that VPC default ranges can be retrieved.
"""
with self.mock_get("/vpcs/default-ranges") as m:
result = self.client.vpcs.default_ranges()
self.assertEqual(m.call_url, "/vpcs/default-ranges")
self.assertIsInstance(result, VPCIPv4DefaultRange)
self.assertEqual(
result.default_ipv4_ranges, ["10.0.0.0/8", "192.168.0.0/17"]
)
self.assertEqual(result.forbidden_ipv4_ranges, ["172.17.0.0/16"])