Skip to main content

Flywheel integration test environment through a Pytest plugin.

Project description

fw-test-env

fw-test-env provides a Flywheel integration test environment that can be used easily as a Pytest plugin.

It uses docker to spin up

  • MongoDB
  • Flywheel Core

fw fixture exposes the following attributes:

  • fw.load - Load test data
  • fw.dump - Dump database
  • fw.reset - Cleanup database
  • fw.db - Pymongo database client
  • fw.client - Get authenticated CoreClient instance (e.g. fw.client.admin)

When using the fw pytest plugin it will load sane defaults into the database. For more details check the default fixture yaml.

Installation

Add as a poetry dev dependency to your project:

poetry add --dev fw-test-env

Usage

import pytest

pytest_plugins = "fw_test_env.pytest_plugin"


def test_core_client(fw):
    resp = fw.client.admin.get("/users/self")
    assert resp["_id"] == "admin@flywheel.test"


# skip creating any acquisition
@pytest.mark.fw_data({"acquisitions": []})
def test_with_custom_defaults(fw):
    resp = fw.client.admin.get("/acquisitions")
    assert len(resp) == 0


# specify the filepath relative to "test/data"
# current limitations: test file name needs to be a valid UUID
# and it should start with '0000' (four zero)
def test_with_files(fw):
    test_file = "00000000-0000-0000-0000-000000000000"
    fw.load({"files": [{"name": "test.txt", "uuid": test_file}]})
    acq_id = fw.dump()["acquisitions"][-1]["_id"]
    resp = fw.client.admin.get(f"/acquisitions/{str(acq_id)}/files/test.txt", raw=True)
    assert resp.content == b"foo bar\n"

For more examples see: test_pytest_fixtures.py

Development

Install the project using poetry and enable pre-commit:

poetry install
pre-commit install

License

MIT

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

fw_test_env-0.1.4-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file fw_test_env-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: fw_test_env-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.3 Linux/5.4.109+

File hashes

Hashes for fw_test_env-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3b16f9c0602c247d99238142abda895f3bc9227a4a9f441a54041581b5fbf28b
MD5 4251f1758daa472b96ce70e950d445a6
BLAKE2b-256 bfa52563e159e594e9c3ca30477cdac7a9e335b2ba2eba794bfc0db9a4b69b2c

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