Creates basic XNAT instance for API tests
Project description
Xnat4Tests provides a helper functions for testing third party tools that access the XNAT API or container service, primarily a means to launch a basic XNAT repository instance within a single Docker container.
The XNAT container service plugin is installed by default and is configured to use the same Docker host as the XNAT instance.
The ‘home/logs’, ‘home/work’, ‘build’, ‘archive’, ‘prearchive’ directories are mounted in from the host for direct access under xnat4tests.config.XNAT_ROOT_DIR, which can be useful for debugging and enables the environment in which containers run in within XNAT’s container service to be mocked.
In addition to the launch_xnat function, which launches the XNAT instance, a connect function is supplied that returns an XnatPy connection object to the test instance
The basic usage is as follows:
# Import xnat4tests functions
from xnat4tests import launch_xnat, stop_xnat, connect, config
# 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()
# Run your tests
with connect() as login:
PROJECT = 'MYPROJECT'
SUBJECT = 'MYSUBJECT'
SESSION = 'MYSESSION'
login.put(f'/data/archive/projects/MY_TEST_PROJECT')
# Create subject
xsubject = login.classes.SubjectData(label=SUBJECT,
parent=login.projects[PROJECT])
# Create session
login.classes.MrSessionData(label=SESSION, parent=xsubject)
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for xnat4tests-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22488a0e53979d39a10dc1e5b38c4d6ebb6d683a4e3b7aee4acb48953e0a2b14 |
|
MD5 | 27cbd261dd74b22d16afd0a4f44cf568 |
|
BLAKE2b-256 | 5c91d506f9799dc0b27110316b459eb76a12b28700cb4747da666be04551b549 |