Skip to content

Commit 8cd47bd

Browse files
committed
wip
1 parent dfa9389 commit 8cd47bd

File tree

3 files changed

+122
-340
lines changed

3 files changed

+122
-340
lines changed

tests/unit/networks/test_client.py

Lines changed: 21 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,30 @@
1515
)
1616
from hcloud.servers import BoundServer
1717

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+
]
1832

19-
class TestBoundNetwork:
2033
@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
2336

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):
2542
bound_network = BoundNetwork(
2643
client=mock.MagicMock(), data=network_response["network"]
2744
)
@@ -49,168 +66,6 @@ def test_bound_network_init(self, network_response):
4966
assert bound_network.routes[0].destination == "10.100.1.0/24"
5067
assert bound_network.routes[0].gateway == "10.0.1.1"
5168

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-
21469

21570
class TestNetworksClient:
21671
@pytest.fixture()

0 commit comments

Comments
 (0)