Skip to content

Commit 4cb28c5

Browse files
committed
Add a real test for Client.restoreData()
1 parent 20af5b8 commit 4cb28c5

1 file changed

Lines changed: 61 additions & 8 deletions

File tree

tests/test_06_ids.py

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
logger = logging.getLogger(__name__)
1919

20+
GiB = 1073741824
2021

2122
class LoggingIDSClient(IDSClient):
2223
"""Modified version of IDSClient that logs some calls.
@@ -26,12 +27,7 @@ def getStatus(self, selection):
2627
logger.debug("getStatus(%s): %s", selection, status, stacklevel=2)
2728
return status
2829

29-
@pytest.fixture(scope="module")
30-
def cleanup(setupicat):
31-
client, conf = getConfig(confSection="root", ids="mandatory")
32-
client.login(conf.auth, conf.credentials)
33-
yield
34-
query = "SELECT df FROM Datafile df WHERE df.location IS NOT NULL"
30+
def _delete_datafiles(client, query):
3531
while True:
3632
try:
3733
client.deleteData(client.search(query))
@@ -40,13 +36,45 @@ def cleanup(setupicat):
4036
else:
4137
break
4238

39+
@pytest.fixture(scope="module")
40+
def cleanup(setupicat):
41+
client, conf = getConfig(confSection="root", ids="mandatory")
42+
client.login(conf.auth, conf.credentials)
43+
yield
44+
query = "SELECT df FROM Datafile df WHERE df.location IS NOT NULL"
45+
_delete_datafiles(client, query)
46+
4347
@pytest.fixture(scope="function")
4448
def client(monkeypatch, cleanup):
4549
monkeypatch.setattr(icat.client, "IDSClient", LoggingIDSClient)
4650
client, conf = getConfig(ids="mandatory")
4751
client.login(conf.auth, conf.credentials)
4852
yield client
4953

54+
@pytest.fixture(scope="function")
55+
def dataset(client, cleanup_objs):
56+
"""A dataset to be used in the test.
57+
58+
The dataset will be eventually be deleted after the test.
59+
"""
60+
inv = client.assertedSearch(Query(client, "Investigation", conditions={
61+
"name": "= '10100601-ST'",
62+
}))[0]
63+
dstype = client.assertedSearch(Query(client, "DatasetType", conditions={
64+
"name": "= 'raw'",
65+
}))[0]
66+
dataset = client.new("Dataset",
67+
name="e208343", complete=False,
68+
investigation=inv, type=dstype)
69+
dataset.create()
70+
cleanup_objs.append(dataset)
71+
yield dataset
72+
query = Query(client, "Datafile", conditions={
73+
"dataset.id": "= %d" % dataset.id,
74+
"location": "IS NOT NULL",
75+
})
76+
_delete_datafiles(client, query)
77+
5078

5179
# ============================ testdata ============================
5280

@@ -412,7 +440,7 @@ def test_restore(client, case):
412440
print("Status of dataset %s is now %s" % (case['dsname'], status))
413441

414442
@pytest.mark.parametrize(("case"), markeddatasets)
415-
def test_restoreData(client, case):
443+
def test_restoreDataCall(client, case):
416444
"""Test the high level call restoreData().
417445
418446
This is essentially a no-op as the dataset in question will
@@ -425,7 +453,7 @@ def test_restoreData(client, case):
425453
assert status == "ONLINE"
426454

427455
@pytest.mark.parametrize(("case"), markeddatasets)
428-
def test_restoreDataSelection(client, case):
456+
def test_restoreDataCallSelection(client, case):
429457
"""Test the high level call restoreData().
430458
431459
Same as last test, but now pass a DataSelection as argument.
@@ -435,6 +463,31 @@ def test_restoreDataSelection(client, case):
435463
status = client.ids.getStatus(selection)
436464
assert status == "ONLINE"
437465

466+
@pytest.mark.slow
467+
def test_restoreData(tmpdirsec, client, dataset):
468+
"""Test restoring data with the high level call restoreData().
469+
470+
This test archives a dataset and calls restoreData() to restore it
471+
again. The size of the dataset is large enough so that restoring
472+
takes some time, so that we actually can observe the call to wait
473+
until the restoring is finished. As a result, the test is rather
474+
slow. It is marked as such and thus disabled by default.
475+
"""
476+
if not client.ids.isTwoLevel():
477+
pytest.skip("This IDS does not use two levels of data storage")
478+
f = DummyDatafile(tmpdirsec, "e208343.nxs", GiB)
479+
query = Query(client, "DatafileFormat", conditions={
480+
"name": "= 'NeXus'",
481+
})
482+
datafileformat = client.assertedSearch(query)[0]
483+
datafile = client.new("Datafile", name=f.fname.name,
484+
dataset=dataset, datafileFormat=datafileformat)
485+
client.putData(f.fname, datafile)
486+
client.ids.archive(DataSelection([dataset]))
487+
client.restoreData([dataset])
488+
status = client.ids.getStatus(DataSelection([dataset]))
489+
assert status == "ONLINE"
490+
438491
@pytest.mark.parametrize(("case"), markeddatasets)
439492
def test_reset(client, case):
440493
"""Call reset() on a dataset.

0 commit comments

Comments
 (0)