Skip to content

Commit cfc6d97

Browse files
committed
feat: rename bound model methods
1 parent f976d80 commit cfc6d97

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

hcloud/storage_boxes/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def _get_self(self) -> BoundStorageBoxSnapshot:
499499
self.data_model.id,
500500
)
501501

502-
def update_snapshot(
502+
def update(
503503
self,
504504
*,
505505
description: str | None = None,
@@ -519,7 +519,7 @@ def update_snapshot(
519519
labels=labels,
520520
)
521521

522-
def delete_snapshot(
522+
def delete(
523523
self,
524524
) -> DeleteStorageBoxSnapshotResponse:
525525
"""
@@ -559,7 +559,7 @@ def _get_self(self) -> BoundStorageBoxSubaccount:
559559
self.data_model.id,
560560
)
561561

562-
def update_subaccount(
562+
def update(
563563
self,
564564
*,
565565
description: str | None = None,
@@ -579,7 +579,7 @@ def update_subaccount(
579579
labels=labels,
580580
)
581581

582-
def delete_subaccount(
582+
def delete(
583583
self,
584584
) -> DeleteStorageBoxSubaccountResponse:
585585
"""
@@ -589,7 +589,7 @@ def delete_subaccount(
589589
"""
590590
return self._client.delete_subaccount(self)
591591

592-
def change_subaccount_home_directory(
592+
def change_home_directory(
593593
self,
594594
home_directory: str,
595595
) -> BoundAction:
@@ -604,7 +604,7 @@ def change_subaccount_home_directory(
604604
self, home_directory=home_directory
605605
)
606606

607-
def reset_subaccount_password(
607+
def reset_password(
608608
self,
609609
password: str,
610610
) -> BoundAction:
@@ -617,7 +617,7 @@ def reset_subaccount_password(
617617
"""
618618
return self._client.reset_subaccount_password(self, password=password)
619619

620-
def update_subaccount_access_settings(
620+
def update_access_settings(
621621
self,
622622
access_settings: StorageBoxSubaccountAccessSettings,
623623
) -> BoundAction:

tests/unit/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def pytest_generate_tests(metafunc: pytest.Metafunc):
170170

171171
class BoundModelTestOptions(TypedDict):
172172
sub_resource: bool
173+
client_method: str
173174

174175

175176
class BoundModelTestCase:
@@ -215,14 +216,19 @@ def test_method(
215216
if isinstance(bound_model_method, tuple):
216217
bound_model_method, options = bound_model_method
217218

219+
resource_client_method_name = options.get(
220+
"client_method",
221+
bound_model_method.__name__,
222+
)
223+
218224
# Check if the resource client has a method named after the bound model method.
219-
assert hasattr(resource_client, bound_model_method.__name__)
225+
assert hasattr(resource_client, resource_client_method_name)
220226

221227
# Mock the resource client method.
222228
resource_client_method_mock = mock.MagicMock()
223229
setattr(
224230
resource_client,
225-
bound_model_method.__name__,
231+
resource_client_method_name,
226232
resource_client_method_mock,
227233
)
228234

tests/unit/storage_boxes/test_client.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def test_init(self, bound_model: BoundStorageBox, resource_client):
127127

128128
class TestBoundStorageBoxSnapshot(BoundModelTestCase):
129129
methods = [
130-
BoundStorageBoxSnapshot.update_snapshot,
131-
BoundStorageBoxSnapshot.delete_snapshot,
130+
(BoundStorageBoxSnapshot.update, {"client_method": "update_snapshot"}),
131+
(BoundStorageBoxSnapshot.delete, {"client_method": "delete_snapshot"}),
132132
]
133133

134134
@pytest.fixture()
@@ -180,11 +180,26 @@ def test_reload(
180180

181181
class TestBoundStorageBoxSubaccount(BoundModelTestCase):
182182
methods = [
183-
BoundStorageBoxSubaccount.update_subaccount,
184-
BoundStorageBoxSubaccount.delete_subaccount,
185-
BoundStorageBoxSubaccount.change_subaccount_home_directory,
186-
BoundStorageBoxSubaccount.reset_subaccount_password,
187-
BoundStorageBoxSubaccount.update_subaccount_access_settings,
183+
(
184+
BoundStorageBoxSubaccount.update,
185+
{"client_method": "update_subaccount"},
186+
),
187+
(
188+
BoundStorageBoxSubaccount.delete,
189+
{"client_method": "delete_subaccount"},
190+
),
191+
(
192+
BoundStorageBoxSubaccount.change_home_directory,
193+
{"client_method": "change_subaccount_home_directory"},
194+
),
195+
(
196+
BoundStorageBoxSubaccount.reset_password,
197+
{"client_method": "reset_subaccount_password"},
198+
),
199+
(
200+
BoundStorageBoxSubaccount.update_access_settings,
201+
{"client_method": "update_subaccount_access_settings"},
202+
),
188203
]
189204

190205
@pytest.fixture()

0 commit comments

Comments
 (0)