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 hashes)

Uploaded Python 3

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