Skip to content

Commit 521ec13

Browse files
committed
fix: support snapshot partial objects
1 parent 56eb5a0 commit 521ec13

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

hcloud/storage_boxes/client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def __init__(
131131

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

134+
def _get_self(self) -> BoundStorageBoxSnapshot:
135+
return self._client.get_snapshot_by_id(
136+
self.data_model.storage_box,
137+
self.data_model.id,
138+
)
139+
134140
# TODO: implement bound methods
135141

136142

@@ -728,7 +734,12 @@ def create_snapshot(
728734
json=data,
729735
)
730736
return CreateStorageBoxSnapshotResponse(
731-
snapshot=BoundStorageBoxSnapshot(self, response["snapshot"]),
737+
snapshot=BoundStorageBoxSnapshot(
738+
self,
739+
response["snapshot"],
740+
# API only returns a partial object.
741+
complete=False,
742+
),
732743
action=BoundAction(self._parent.actions, response["action"]),
733744
)
734745

tests/unit/storage_boxes/test_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ def test_init(self, bound_model: BoundStorageBoxSnapshot, resource_client):
119119
assert o.stats.size_filesystem == 3949572745
120120
assert o.created == isoparse("2025-11-10T19:16:57Z")
121121

122+
def test_reload(
123+
self,
124+
request_mock: mock.MagicMock,
125+
resource_client: StorageBoxesClient,
126+
storage_box_snapshot1,
127+
):
128+
o = BoundStorageBoxSnapshot(resource_client, data={"id": 34, "storage_box": 42})
129+
130+
request_mock.return_value = {"snapshot": storage_box_snapshot1}
131+
132+
o.reload()
133+
134+
request_mock.assert_called_with(
135+
method="GET",
136+
url="/storage_boxes/42/snapshots/34",
137+
)
138+
139+
assert o.labels is not None
140+
122141

123142
class TestStorageBoxClient:
124143
@pytest.fixture()

0 commit comments

Comments
 (0)