Skip to content

Commit

Permalink
Testing to see whether session directories are accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Jan 21, 2022
1 parent 1312bfc commit 9d10ccd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
44 changes: 27 additions & 17 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
@@ -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()

assert [p.name for p in (config.XNAT_ROOT_DIR / 'archive' / PROJECT / 'arc001').iterdir()] == [SESSION]
1 change: 1 addition & 0 deletions xnat4tests/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down

0 comments on commit 9d10ccd

Please sign in to comment.