Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions hcloud/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ def __getattr__(self, name: str): # type: ignore[no-untyped-def]
value = getattr(self.data_model, name)
return value

def reload(self) -> None:
"""Reloads the model and tries to get all data from the APIx"""
def _get_self(self) -> BoundModelBase:
assert hasattr(self._client, "get_by_id")
bound_model = self._client.get_by_id(self.data_model.id)
return self._client.get_by_id(self.data_model.id)

def reload(self) -> None:
"""Reloads the model and tries to get all data from the API"""
bound_model = self._get_self()
self.data_model = bound_model.data_model
self.complete = True

Expand Down
7 changes: 7 additions & 0 deletions hcloud/zones/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ def __init__(self, client: ZonesClient, data: dict, complete: bool = True):

super().__init__(client, data, complete)

def _get_self(self) -> BoundZoneRRSet:
return self._client.get_rrset(
self.data_model.zone,
self.data_model.name,
self.data_model.type,
)

def update_rrset(
self,
*,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ def test_method_list(self, bound_model):
lambda m: inspect.ismethod(m)
and m.__func__ in bound_model.__class__.__dict__.values(),
):
# Ignore private methods
if name.startswith("_"):
continue

# Actions methods are already tested in TestBoundModelActions.
if name in ("__init__", "get_actions", "get_actions_list"):
continue
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/zones/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,25 @@ def test_init(self, resource_client: ZonesClient, bound_model: BoundZoneRRSet):

assert isinstance(o.zone, BoundZone)
assert o.zone.id == 42

def test_reload(
self,
request_mock: mock.MagicMock,
resource_client: ZonesClient,
zone_rrset1,
):
o = BoundZoneRRSet(
resource_client,
data={"id": "www/A", "zone": 42},
complete=False,
)
request_mock.return_value = {"rrset": zone_rrset1}

o.reload()

request_mock.assert_called_with(
method="GET",
url="/zones/42/rrsets/www/A",
)

assert o.labels is not None