Skip to main content

Creates basic XNAT instance for API tests

Project description

https://github.com/australian-imaging-service/xnat4tests/actions/workflows/test.yml/badge.svg https://img.shields.io/pypi/v/xnat4tests.svg

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

Installation

Xnat4Tests is available on PyPI so to install, simply use pip

$ pip3 install xnat4tests

or include in your package’s test_requires.

Usage

# 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()

Alternatively, if you are using Pytest then you can set up the connection as a fixture in your conftest.py with

@pytest.fixture(scope='session')
def xnat_login():
    xnat4tests.launch_xnat()
    yield xnat4tests.connect()
    xnat4tests.stop_xnat()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

xnat4tests-0.2.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file xnat4tests-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: xnat4tests-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for xnat4tests-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2668c31983d93dac20b4bafac7a2bd9f475a0f948682d445400af2190d914f59
MD5 3559d3441c1f6e28ebb699a7d93af9c5
BLAKE2b-256 a78c37fc8a99d7434d53e2a9f2db2414f2320e4c2f5fa1214a0fac7ecd66a662

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page