Skip to content

Commit 6774fe4

Browse files
committed
fixes after rebase
1 parent 347a2ed commit 6774fe4

File tree

2 files changed

+44
-50
lines changed

2 files changed

+44
-50
lines changed

hcloud/storage_boxes/client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def __init__(
3434
raw = data.get("storage_box_type")
3535
if raw is not None:
3636
data["storage_box_type"] = BoundStorageBoxType(
37-
client._client.storage_box_types, raw
37+
client._parent.storage_box_types, raw
3838
)
3939

4040
raw = data.get("location")
4141
if raw is not None:
42-
data["location"] = BoundLocation(client._client.locations, raw)
42+
data["location"] = BoundLocation(client._parent.locations, raw)
4343

4444
raw = data.get("snapshot_plan")
4545
if raw is not None:
@@ -70,7 +70,9 @@ class StorageBoxesClient(ResourceClientBase):
7070
See https://docs.hetzner.cloud/reference/hetzner#storage-boxes.
7171
"""
7272

73-
_client: Client
73+
def __init__(self, client: Client):
74+
super().__init__(client)
75+
self._client = client._client_hetzner
7476

7577
def get_by_id(self, id: int) -> BoundStorageBox:
7678
"""
@@ -80,7 +82,7 @@ def get_by_id(self, id: int) -> BoundStorageBox:
8082
8183
:param id: ID of the Storage Box.
8284
"""
83-
response = self._client._request_hetzner( # pylint: disable=protected-access
85+
response = self._client.request(
8486
method="GET",
8587
url=f"/storage_boxes/{id}",
8688
)
@@ -123,7 +125,7 @@ def get_list(
123125
if per_page is not None:
124126
params["per_page"] = per_page
125127

126-
response = self._client._request_hetzner( # pylint: disable=protected-access
128+
response = self._client.request(
127129
method="GET",
128130
url="/storage_boxes",
129131
params=params,
@@ -189,15 +191,15 @@ def create(
189191
if labels is not None:
190192
data["labels"] = labels
191193

192-
response = self._client._request_hetzner( # pylint: disable=protected-access
194+
response = self._client.request(
193195
method="POST",
194196
url="/storage_boxes",
195197
json=data,
196198
)
197199

198200
return CreateStorageBoxResponse(
199201
storage_box=BoundStorageBox(self, response["storage_box"]),
200-
action=BoundAction(self._client.actions, response["action"]),
202+
action=BoundAction(self._parent.actions, response["action"]),
201203
)
202204

203205
def update(
@@ -222,7 +224,7 @@ def update(
222224
if labels is not None:
223225
data["labels"] = labels
224226

225-
response = self._client._request_hetzner( # pylint: disable=protected-access
227+
response = self._client.request(
226228
method="PUT",
227229
url=f"/storage_boxes/{storage_box.id}",
228230
json=data,
@@ -241,13 +243,13 @@ def delete(
241243
242244
:param storage_box: Storage Box to delete.
243245
"""
244-
response = self._client._request_hetzner( # pylint: disable=protected-access
246+
response = self._client.request(
245247
method="DELETE",
246248
url=f"/storage_boxes/{storage_box.id}",
247249
)
248250

249251
return DeleteStorageBoxResponse(
250-
action=BoundAction(self._client.actions, response["action"])
252+
action=BoundAction(self._parent.actions, response["action"])
251253
)
252254

253255
def get_folders(
@@ -269,7 +271,7 @@ def get_folders(
269271
if path is not None:
270272
params["path"] = path
271273

272-
response = self._client._request_hetzner( # pylint: disable=protected-access
274+
response = self._client.request(
273275
method="GET",
274276
url=f"/storage_boxes/{storage_box.id}/folders",
275277
params=params,

tests/unit/storage_boxes/test_client.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
def assert_bound_model(
2323
o: BoundStorageBox,
24-
client: StorageBoxesClient,
24+
resource_client: StorageBoxesClient,
2525
):
2626
assert isinstance(o, BoundStorageBox)
27-
assert o._client is client
27+
assert o._client is resource_client
2828
assert o.id == 42
2929
assert o.name == "storage-box1"
3030

@@ -38,35 +38,27 @@ def assert_bound_action(
3838
assert o.id == 22
3939

4040

41-
@pytest.fixture(name="request_mock")
42-
def request_mock_fixture():
43-
return mock.MagicMock()
44-
45-
46-
@pytest.fixture(name="client")
47-
def client_fixture(request_mock) -> StorageBoxesClient:
48-
client = Client("")
49-
client._request_hetzner = request_mock
50-
return StorageBoxesClient(client=client)
51-
52-
5341
class TestClient:
42+
@pytest.fixture()
43+
def resource_client(self, client: Client) -> StorageBoxesClient:
44+
return StorageBoxesClient(client)
45+
5446
def test_get_by_id(
5547
self,
5648
request_mock: mock.MagicMock,
57-
client: StorageBoxesClient,
49+
resource_client: StorageBoxesClient,
5850
storage_box1,
5951
):
6052
request_mock.return_value = {"storage_box": storage_box1}
6153

62-
result = client.get_by_id(42)
54+
result = resource_client.get_by_id(42)
6355

6456
request_mock.assert_called_with(
6557
method="GET",
6658
url="/storage_boxes/42",
6759
)
6860

69-
assert_bound_model(result, client)
61+
assert_bound_model(result, resource_client)
7062
assert result.storage_box_type.id == 42
7163
assert result.storage_box_type.name == "bx11"
7264
assert result.location.id == 1
@@ -102,14 +94,14 @@ def test_get_by_id(
10294
def test_get_list(
10395
self,
10496
request_mock: mock.MagicMock,
105-
client: StorageBoxesClient,
97+
resource_client: StorageBoxesClient,
10698
storage_box1,
10799
storage_box2,
108100
params,
109101
):
110102
request_mock.return_value = {"storage_boxes": [storage_box1, storage_box2]}
111103

112-
result = client.get_list(**params)
104+
result = resource_client.get_list(**params)
113105

114106
request_mock.assert_called_with(
115107
url="/storage_boxes",
@@ -123,11 +115,11 @@ def test_get_list(
123115
result1 = result.storage_boxes[0]
124116
result2 = result.storage_boxes[1]
125117

126-
assert result1._client is client
118+
assert result1._client is resource_client
127119
assert result1.id == 42
128120
assert result1.name == "storage-box1"
129121

130-
assert result2._client is client
122+
assert result2._client is resource_client
131123
assert result2.id == 43
132124
assert result2.name == "storage-box2"
133125

@@ -141,14 +133,14 @@ def test_get_list(
141133
def test_get_all(
142134
self,
143135
request_mock: mock.MagicMock,
144-
client: StorageBoxesClient,
136+
resource_client: StorageBoxesClient,
145137
storage_box1,
146138
storage_box2,
147139
params,
148140
):
149141
request_mock.return_value = {"storage_boxes": [storage_box1, storage_box2]}
150142

151-
result = client.get_all(**params)
143+
result = resource_client.get_all(**params)
152144

153145
request_mock.assert_called_with(
154146
url="/storage_boxes",
@@ -161,23 +153,23 @@ def test_get_all(
161153
result1 = result[0]
162154
result2 = result[1]
163155

164-
assert result1._client is client
156+
assert result1._client is resource_client
165157
assert result1.id == 42
166158
assert result1.name == "storage-box1"
167159

168-
assert result2._client is client
160+
assert result2._client is resource_client
169161
assert result2.id == 43
170162
assert result2.name == "storage-box2"
171163

172164
def test_get_by_name(
173165
self,
174166
request_mock: mock.MagicMock,
175-
client: StorageBoxesClient,
167+
resource_client: StorageBoxesClient,
176168
storage_box1,
177169
):
178170
request_mock.return_value = {"storage_boxes": [storage_box1]}
179171

180-
result = client.get_by_name("bx11")
172+
result = resource_client.get_by_name("bx11")
181173

182174
params = {"name": "bx11"}
183175

@@ -187,12 +179,12 @@ def test_get_by_name(
187179
params=params,
188180
)
189181

190-
assert_bound_model(result, client)
182+
assert_bound_model(result, resource_client)
191183

192184
def test_create(
193185
self,
194186
request_mock: mock.MagicMock,
195-
client: StorageBoxesClient,
187+
resource_client: StorageBoxesClient,
196188
storage_box1,
197189
action_running1,
198190
):
@@ -201,7 +193,7 @@ def test_create(
201193
"action": action_running1,
202194
}
203195

204-
result = client.create(
196+
result = resource_client.create(
205197
name="storage-box1",
206198
password="secret-password",
207199
location=Location(name="fsn1"),
@@ -233,19 +225,19 @@ def test_create(
233225
},
234226
)
235227

236-
assert_bound_model(result.storage_box, client)
228+
assert_bound_model(result.storage_box, resource_client)
237229

238230
def test_update(
239231
self,
240232
request_mock: mock.MagicMock,
241-
client: StorageBoxesClient,
233+
resource_client: StorageBoxesClient,
242234
storage_box1,
243235
):
244236
request_mock.return_value = {
245237
"storage_box": storage_box1,
246238
}
247239

248-
result = client.update(
240+
result = resource_client.update(
249241
StorageBox(id=42),
250242
name="name",
251243
labels={"key": "value"},
@@ -260,26 +252,26 @@ def test_update(
260252
},
261253
)
262254

263-
assert_bound_model(result, client)
255+
assert_bound_model(result, resource_client)
264256

265257
def test_delete(
266258
self,
267259
request_mock: mock.MagicMock,
268-
client: StorageBoxesClient,
260+
resource_client: StorageBoxesClient,
269261
action_running1,
270262
):
271263
request_mock.return_value = {
272264
"action": action_running1,
273265
}
274266

275-
result = client.delete(StorageBox(id=42))
267+
result = resource_client.delete(StorageBox(id=42))
276268

277269
request_mock.assert_called_with(
278270
method="DELETE",
279271
url="/storage_boxes/42",
280272
)
281273

282-
assert_bound_action(result.action, client._client.actions)
274+
assert_bound_action(result.action, resource_client._parent.actions)
283275

284276
@pytest.mark.parametrize(
285277
"params",
@@ -291,14 +283,14 @@ def test_delete(
291283
def test_get_folders(
292284
self,
293285
request_mock: mock.MagicMock,
294-
client: StorageBoxesClient,
286+
resource_client: StorageBoxesClient,
295287
params,
296288
):
297289
request_mock.return_value = {
298290
"folders": ["dir1", "dir2"],
299291
}
300292

301-
result = client.get_folders(StorageBox(id=42), **params)
293+
result = resource_client.get_folders(StorageBox(id=42), **params)
302294

303295
request_mock.assert_called_with(
304296
method="GET", url="/storage_boxes/42/folders", params=params

0 commit comments

Comments
 (0)