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 datafw.dump- Dump databasefw.reset- Cleanup databasefw.db- Pymongo database clientfw.client- Get authenticatedCoreClientinstance (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
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)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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+
|