Skip to main content

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

Metadata

Release files for fw-test-env 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fw-test-env 0.1.4
File Interpreter ABI Platform
fw_test_env-0.1.4-py3-none-any.whl Python 3 none any Details

Release files / fw_test_env-0.1.4-py3-none-any.whl

Download URL fw_test_env-0.1.4-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b16f9c0602c247d99238142abda895f3bc9227a4a9f441a54041581b5fbf28b
BLAKE2b-256 checksum
How to use checksums
bfa52563e159e594e9c3ca30477cdac7a9e335b2ba2eba794bfc0db9a4b69b2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.3 Linux/5.4.109+

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page