From 9d10ccdcf05c19c7811fbfec2e592a069afcb027 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 21 Jan 2022 11:07:02 +1100 Subject: [PATCH] Testing to see whether session directories are accessible --- tests/test_launch.py | 44 +++++++++++++++++++++++++++----------------- xnat4tests/launch.py | 1 + 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/tests/test_launch.py b/tests/test_launch.py index 6be67a5..3e17909 100644 --- a/tests/test_launch.py +++ b/tests/test_launch.py @@ -1,30 +1,40 @@ +import tempfile +from pathlib import Path +import pytest from xnat4tests import launch_xnat, stop_xnat, connect, config -def test_launch(): +@pytest.fixture(scope='session') +def login(): + launch_xnat() + yield connect() + stop_xnat() + + +def test_launch(login): PROJECT = 'MY_TEST_PROJECT' SUBJECT = 'MY_TEST_SUBJECT' SESSION = 'MY_TEST_SESSION' - # Launch the instance (NB: it takes quite while for an XNAT instance to start). If an existing - # container with the reserved name is already running it is returned instead - launch_xnat() + # Create project + login.put(f'/data/archive/projects/{PROJECT}') - # Run your tests - with connect() as login: - # Create project - login.put(f'/data/archive/projects/{PROJECT}') + # Create subject + xsubject = login.classes.SubjectData(label=SUBJECT, + parent=login.projects[PROJECT]) + # Create session + xsession = login.classes.MrSessionData(label=SESSION, parent=xsubject) - # Create subject - xsubject = login.classes.SubjectData(label=SUBJECT, - parent=login.projects[PROJECT]) - # Create session - login.classes.MrSessionData(label=SESSION, parent=xsubject) + temp_dir = Path(tempfile.mkdtemp()) + a_file = temp_dir / 'a_file.txt' + with open(a_file, 'w') as f: + f.write('a file') + + xresource = login.classes.ResourceCatalog( + parent=xsession, label='A_RESOURCE', format='text') + xresource.upload(str(a_file), 'a_file') assert [p.name for p in (config.XNAT_ROOT_DIR / 'archive').iterdir()] == [PROJECT] - - # Remove the container after you are done (not strictly necessary) - stop_xnat() - \ No newline at end of file + assert [p.name for p in (config.XNAT_ROOT_DIR / 'archive' / PROJECT / 'arc001').iterdir()] == [SESSION] diff --git a/xnat4tests/launch.py b/xnat4tests/launch.py index 68afef7..8b84f95 100644 --- a/xnat4tests/launch.py +++ b/xnat4tests/launch.py @@ -55,6 +55,7 @@ def launch_xnat(): stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | + stat.S_IXOTH | stat.S_ISGID) volumes[str(dpath)] = {'bind': '/data/xnat/' + dname, 'mode': 'rw'}