|
15 | 15 | ) |
16 | 16 | from hcloud.servers import BoundServer |
17 | 17 |
|
| 18 | +from ..conftest import BoundModelTestCase |
| 19 | + |
| 20 | + |
| 21 | +class TestBoundNetwork(BoundModelTestCase): |
| 22 | + methods = [ |
| 23 | + BoundNetwork.update, |
| 24 | + BoundNetwork.delete, |
| 25 | + BoundNetwork.add_subnet, |
| 26 | + BoundNetwork.delete_subnet, |
| 27 | + BoundNetwork.add_route, |
| 28 | + BoundNetwork.delete_route, |
| 29 | + BoundNetwork.change_ip_range, |
| 30 | + BoundNetwork.change_protection, |
| 31 | + ] |
18 | 32 |
|
19 | | -class TestBoundNetwork: |
20 | 33 | @pytest.fixture() |
21 | | - def bound_network(self, client: Client): |
22 | | - return BoundNetwork(client.networks, data=dict(id=14)) |
| 34 | + def resource_client(self, client: Client): |
| 35 | + return client.networks |
23 | 36 |
|
24 | | - def test_bound_network_init(self, network_response): |
| 37 | + @pytest.fixture() |
| 38 | + def bound_model(self, resource_client: NetworksClient): |
| 39 | + return BoundNetwork(resource_client, data=dict(id=14)) |
| 40 | + |
| 41 | + def test_init(self, network_response): |
25 | 42 | bound_network = BoundNetwork( |
26 | 43 | client=mock.MagicMock(), data=network_response["network"] |
27 | 44 | ) |
@@ -49,168 +66,6 @@ def test_bound_network_init(self, network_response): |
49 | 66 | assert bound_network.routes[0].destination == "10.100.1.0/24" |
50 | 67 | assert bound_network.routes[0].gateway == "10.0.1.1" |
51 | 68 |
|
52 | | - def test_update( |
53 | | - self, |
54 | | - request_mock: mock.MagicMock, |
55 | | - bound_network, |
56 | | - response_update_network, |
57 | | - ): |
58 | | - request_mock.return_value = response_update_network |
59 | | - |
60 | | - network = bound_network.update(name="new-name") |
61 | | - |
62 | | - request_mock.assert_called_with( |
63 | | - method="PUT", |
64 | | - url="/networks/14", |
65 | | - json={"name": "new-name"}, |
66 | | - ) |
67 | | - |
68 | | - assert network.id == 4711 |
69 | | - assert network.name == "new-name" |
70 | | - |
71 | | - def test_delete( |
72 | | - self, |
73 | | - request_mock: mock.MagicMock, |
74 | | - bound_network, |
75 | | - action_response, |
76 | | - ): |
77 | | - request_mock.return_value = action_response |
78 | | - |
79 | | - delete_success = bound_network.delete() |
80 | | - |
81 | | - request_mock.assert_called_with( |
82 | | - method="DELETE", |
83 | | - url="/networks/14", |
84 | | - ) |
85 | | - |
86 | | - assert delete_success is True |
87 | | - |
88 | | - def test_change_protection( |
89 | | - self, |
90 | | - request_mock: mock.MagicMock, |
91 | | - bound_network, |
92 | | - action_response, |
93 | | - ): |
94 | | - request_mock.return_value = action_response |
95 | | - |
96 | | - action = bound_network.change_protection(True) |
97 | | - |
98 | | - request_mock.assert_called_with( |
99 | | - method="POST", |
100 | | - url="/networks/14/actions/change_protection", |
101 | | - json={"delete": True}, |
102 | | - ) |
103 | | - |
104 | | - assert action.id == 1 |
105 | | - assert action.progress == 0 |
106 | | - |
107 | | - def test_add_subnet( |
108 | | - self, |
109 | | - request_mock: mock.MagicMock, |
110 | | - bound_network, |
111 | | - action_response, |
112 | | - ): |
113 | | - request_mock.return_value = action_response |
114 | | - |
115 | | - subnet = NetworkSubnet( |
116 | | - type=NetworkSubnet.TYPE_CLOUD, |
117 | | - ip_range="10.0.1.0/24", |
118 | | - network_zone="eu-central", |
119 | | - ) |
120 | | - action = bound_network.add_subnet(subnet) |
121 | | - |
122 | | - request_mock.assert_called_with( |
123 | | - method="POST", |
124 | | - url="/networks/14/actions/add_subnet", |
125 | | - json={ |
126 | | - "type": NetworkSubnet.TYPE_CLOUD, |
127 | | - "ip_range": "10.0.1.0/24", |
128 | | - "network_zone": "eu-central", |
129 | | - }, |
130 | | - ) |
131 | | - |
132 | | - assert action.id == 1 |
133 | | - assert action.progress == 0 |
134 | | - |
135 | | - def test_delete_subnet( |
136 | | - self, |
137 | | - request_mock: mock.MagicMock, |
138 | | - bound_network, |
139 | | - action_response, |
140 | | - ): |
141 | | - request_mock.return_value = action_response |
142 | | - |
143 | | - subnet = NetworkSubnet(ip_range="10.0.1.0/24") |
144 | | - action = bound_network.delete_subnet(subnet) |
145 | | - |
146 | | - request_mock.assert_called_with( |
147 | | - method="POST", |
148 | | - url="/networks/14/actions/delete_subnet", |
149 | | - json={"ip_range": "10.0.1.0/24"}, |
150 | | - ) |
151 | | - |
152 | | - assert action.id == 1 |
153 | | - assert action.progress == 0 |
154 | | - |
155 | | - def test_add_route( |
156 | | - self, |
157 | | - request_mock: mock.MagicMock, |
158 | | - bound_network, |
159 | | - action_response, |
160 | | - ): |
161 | | - request_mock.return_value = action_response |
162 | | - |
163 | | - route = NetworkRoute(destination="10.100.1.0/24", gateway="10.0.1.1") |
164 | | - action = bound_network.add_route(route) |
165 | | - |
166 | | - request_mock.assert_called_with( |
167 | | - method="POST", |
168 | | - url="/networks/14/actions/add_route", |
169 | | - json={"destination": "10.100.1.0/24", "gateway": "10.0.1.1"}, |
170 | | - ) |
171 | | - |
172 | | - assert action.id == 1 |
173 | | - assert action.progress == 0 |
174 | | - |
175 | | - def test_delete_route( |
176 | | - self, |
177 | | - request_mock: mock.MagicMock, |
178 | | - bound_network, |
179 | | - action_response, |
180 | | - ): |
181 | | - request_mock.return_value = action_response |
182 | | - |
183 | | - route = NetworkRoute(destination="10.100.1.0/24", gateway="10.0.1.1") |
184 | | - action = bound_network.delete_route(route) |
185 | | - |
186 | | - request_mock.assert_called_with( |
187 | | - method="POST", |
188 | | - url="/networks/14/actions/delete_route", |
189 | | - json={"destination": "10.100.1.0/24", "gateway": "10.0.1.1"}, |
190 | | - ) |
191 | | - |
192 | | - assert action.id == 1 |
193 | | - assert action.progress == 0 |
194 | | - |
195 | | - def test_change_ip( |
196 | | - self, |
197 | | - request_mock: mock.MagicMock, |
198 | | - bound_network, |
199 | | - action_response, |
200 | | - ): |
201 | | - request_mock.return_value = action_response |
202 | | - |
203 | | - action = bound_network.change_ip_range("10.0.0.0/12") |
204 | | - |
205 | | - request_mock.assert_called_with( |
206 | | - method="POST", |
207 | | - url="/networks/14/actions/change_ip_range", |
208 | | - json={"ip_range": "10.0.0.0/12"}, |
209 | | - ) |
210 | | - |
211 | | - assert action.id == 1 |
212 | | - assert action.progress == 0 |
213 | | - |
214 | 69 |
|
215 | 70 | class TestNetworksClient: |
216 | 71 | @pytest.fixture() |
|
0 commit comments