Skip to content

Commit c896beb

Browse files
committed
TST: add unit test for 'restore_items' API
1 parent 00d51fc commit c896beb

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/save_and_restore_api/_api_threads.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ def restore_node(self, nodeId, *, auth=None):
282282
"""
283283
Restore PVs based on the data from an existing snapshot node specified by nodeId.
284284
285+
Returns a list of snapshotItems that were NOT restored. Ideally the list should be empty.
286+
285287
API: POST /restore/node
286288
"""
287289
method, url, url_params = self._prepare_restore_node(nodeId=nodeId)
@@ -292,6 +294,8 @@ def restore_items(self, *, snapshotItems, auth=None):
292294
Restore PVs based on the list of snapshot items passed with the request. The list
293295
format matches the format of ``snapshotData["snapshotItems"]``
294296
297+
Returns a list of snapshotItems that were NOT restored. Ideally the list should be empty.
298+
295299
API: POST /restore/items
296300
"""
297301
method, url, params = self._prepare_restore_items(snapshotItems=snapshotItems)

tests/test_snapshot_control.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,13 @@ async def testing():
334334
# =============================================================================================
335335

336336
# fmt: off
337+
@pytest.mark.parametrize("restorenode", [True, False])
337338
@pytest.mark.parametrize("usesetauth", [True, False])
338339
@pytest.mark.parametrize("library", ["THREADS", "ASYNC"])
339340
# fmt: on
340-
def test_restore_node_01(clear_sar, library, usesetauth): # noqa: F811
341+
def test_restore_node_01(clear_sar, library, usesetauth, restorenode): # noqa: F811
341342
"""
342-
Basic tests for the 'restore_node' API.
343+
Basic tests for the 'restore_node' and 'restore_items' API.
343344
"""
344345
root_folder_uid = create_root_folder()
345346
name, comment = "test snapshot", "This is a test snapshot"
@@ -369,9 +370,13 @@ def test_restore_node_01(clear_sar, library, usesetauth): # noqa: F811
369370
for pv in ioc_pvs.keys():
370371
caput(pv, "0")
371372

372-
response = SR.restore_node(shot_uid, **auth)
373+
if restorenode:
374+
response = SR.restore_node(shot_uid, **auth)
375+
else:
376+
response = SR.restore_items(snapshotItems=snapshotData["snapshotItems"], **auth)
377+
373378
print(f"response: {response}")
374-
assert len(response) == 0 # Empty if restoration succeeded
379+
assert len(response) == 0
375380

376381
for pv, v in ioc_pvs.items():
377382
assert int(caget(pv, "0")) == int(v), f"PV {pv} has value {caget(pv)}, expected {v}"
@@ -402,7 +407,11 @@ async def testing():
402407
for pv in ioc_pvs.keys():
403408
caput(pv, "0")
404409

405-
response = await SR.restore_node(shot_uid, **auth)
410+
if restorenode:
411+
response = await SR.restore_node(shot_uid, **auth)
412+
else:
413+
response = await SR.restore_items(snapshotItems=snapshotData["snapshotItems"], **auth)
414+
406415
print(f"response: {response}")
407416
assert len(response) == 0 # Empty if restoration succeeded
408417

0 commit comments

Comments
 (0)