Skip to content

Commit 00d51fc

Browse files
committed
TST: unit tests for 'restore_node' API
1 parent 69c5caa commit 00d51fc

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

tests/test_snapshot_control.py

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44

55
import pytest
6-
from epics import caget
6+
from epics import caget, caput
77

88
from save_and_restore_api import SaveRestoreAPI as SaveRestoreAPI_Threads
99
from save_and_restore_api.aio import SaveRestoreAPI as SaveRestoreAPI_Async
@@ -197,7 +197,7 @@ async def testing():
197197
@pytest.mark.parametrize("usesetauth", [True, False])
198198
@pytest.mark.parametrize("library", ["THREADS", "ASYNC"])
199199
# fmt: on
200-
def test_take_snapshot_add_01(clear_sar, library, usesetauth): # noqa: F811
200+
def test_snapshot_add_01(clear_sar, library, usesetauth): # noqa: F811
201201
"""
202202
Basic tests for the 'snapshot_add', 'snapshot_update' and 'snapshots_get' API.
203203
"""
@@ -327,3 +327,86 @@ async def testing():
327327
assert {shot_uid_1, shot_uid_2}.issubset(set(uids))
328328

329329
asyncio.run(testing())
330+
331+
332+
# =============================================================================================
333+
# TESTS FOR SNAPSHOT-RESTORE-CONTROLLER API METHODS
334+
# =============================================================================================
335+
336+
# fmt: off
337+
@pytest.mark.parametrize("usesetauth", [True, False])
338+
@pytest.mark.parametrize("library", ["THREADS", "ASYNC"])
339+
# fmt: on
340+
def test_restore_node_01(clear_sar, library, usesetauth): # noqa: F811
341+
"""
342+
Basic tests for the 'restore_node' API.
343+
"""
344+
root_folder_uid = create_root_folder()
345+
name, comment = "test snapshot", "This is a test snapshot"
346+
347+
if not _is_async(library):
348+
with SaveRestoreAPI_Threads(base_url=base_url, timeout=10) as SR:
349+
auth = _select_auth(SR=SR, usesetauth=usesetauth)
350+
351+
configurationNode = {"name": "Test Config"}
352+
configurationData = {"pvList": [{"pvName": _} for _ in ioc_pvs.keys()]}
353+
354+
response = SR.config_create(
355+
root_folder_uid,
356+
configurationNode=configurationNode,
357+
configurationData=configurationData,
358+
**auth
359+
)
360+
config_uid = response["configurationNode"]["uniqueId"]
361+
362+
# Take a single snapshot (snapshot #1)
363+
response = SR.take_snapshot_save(config_uid, name=name, comment=comment, **auth)
364+
shot_uid = response["snapshotNode"]["uniqueId"]
365+
snapshotData = response["snapshotData"]
366+
print(f"snapshotData: {snapshotData}")
367+
368+
# Change all the PVs to zero
369+
for pv in ioc_pvs.keys():
370+
caput(pv, "0")
371+
372+
response = SR.restore_node(shot_uid, **auth)
373+
print(f"response: {response}")
374+
assert len(response) == 0 # Empty if restoration succeeded
375+
376+
for pv, v in ioc_pvs.items():
377+
assert int(caget(pv, "0")) == int(v), f"PV {pv} has value {caget(pv)}, expected {v}"
378+
379+
else:
380+
async def testing():
381+
async with SaveRestoreAPI_Async(base_url=base_url, timeout=2) as SR:
382+
auth = _select_auth(SR=SR, usesetauth=usesetauth)
383+
384+
configurationNode = {"name": "Test Config"}
385+
configurationData = {"pvList": [{"pvName": _} for _ in ioc_pvs.keys()]}
386+
387+
response = await SR.config_create(
388+
root_folder_uid,
389+
configurationNode=configurationNode,
390+
configurationData=configurationData,
391+
**auth
392+
)
393+
config_uid = response["configurationNode"]["uniqueId"]
394+
395+
# Take a single snapshot (snapshot #1)
396+
response = await SR.take_snapshot_save(config_uid, name=name, comment=comment, **auth)
397+
shot_uid = response["snapshotNode"]["uniqueId"]
398+
snapshotData = response["snapshotData"]
399+
print(f"snapshotData: {snapshotData}")
400+
401+
# Change all the PVs to zero
402+
for pv in ioc_pvs.keys():
403+
caput(pv, "0")
404+
405+
response = await SR.restore_node(shot_uid, **auth)
406+
print(f"response: {response}")
407+
assert len(response) == 0 # Empty if restoration succeeded
408+
409+
for pv, v in ioc_pvs.items():
410+
assert int(caget(pv, "0")) == int(v), f"PV {pv} has value {caget(pv)}, expected {v}"
411+
412+
asyncio.run(testing())

0 commit comments

Comments
 (0)