Pytest fixtures and utilities for testing Flaxon applications
Project description
flaxon-pytest
Pytest fixtures and utilities for testing Flaxon applications.
Installation
pip install flaxon-pytest
Quick Start
python
from flaxon import Flaxon
app = Flaxon("test-app")
@app.get("/")
async def home():
return {"message": "Hello"}
def test_home(flaxon_client):
response = flaxon_client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello"}
Fixtures
flaxon_client
Synchronous test client.
python
def test_route(flaxon_client):
response = flaxon_client.get("/")
assert response.status_code == 200
flaxon_async_client
Asynchronous test client.
python
@pytest.mark.asyncio
async def test_route(flaxon_async_client):
response = await flaxon_async_client.get("/")
assert response.status_code == 200
flaxon_app
Create a test application.
python
def test_custom_app(flaxon_app):
@flaxon_app.get("/custom")
async def custom():
return {"ok": True}
client = flaxon_app.test_client()
response = client.get("/custom")
assert response.status_code == 200
flaxon_websocket_client
WebSocket test client.
python
@pytest.mark.asyncio
async def test_websocket(flaxon_websocket_client):
await flaxon_websocket_client.connect("/ws/echo")
await flaxon_websocket_client.send_json({"message": "Hello"})
response = await flaxon_websocket_client.receive_json()
assert response["message"] == "Hello"
await flaxon_websocket_client.disconnect()
flaxon_temp_dir
Temporary directory for file tests.
python
def test_upload(flaxon_client, flaxon_temp_dir):
file_path = flaxon_temp_dir / "test.txt"
file_path.write_text("Hello")
# Upload file...
flaxon_db
In-memory database for tests.
python
async def test_db(flaxon_db):
await flaxon_db.execute("CREATE TABLE users (id INTEGER, name TEXT)")
await flaxon_db.execute("INSERT INTO users VALUES (1, 'Alice')")
row = await flaxon_db.fetch_one("SELECT * FROM users")
assert row["name"] == "Alice"
Assertions
assert_status
python
from flaxon_pytest import assert_status
assert_status(response, 200)
assert_json
python
from flaxon_pytest import assert_json
data = assert_json(response)
assert data["success"] is True
assert_success
python
from flaxon_pytest import assert_success
assert_success(response)
assert_error
python
from flaxon_pytest import assert_error
assert_error(response, code="FX-VAL-001")
assert_header
python
from flaxon_pytest import assert_header
assert_header(response, "x-request-id")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flaxon_pytest-0.1.0.tar.gz
(9.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flaxon_pytest-0.1.0.tar.gz.
File metadata
- Download URL: flaxon_pytest-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81752ae17c280ce058d674dcba54b98ef0c056d63c8921c85854b819c2007114
|
|
| MD5 |
832a61547ca192143da3b100c3531134
|
|
| BLAKE2b-256 |
665cdb1e8d5444b77a95fe4d24f214584fc7356be5df9d1231816c8c09540bac
|
File details
Details for the file flaxon_pytest-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flaxon_pytest-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f596ffcb5f027a9602722a8ba0bb32c537a4d44349239b3f534c02398338ea0c
|
|
| MD5 |
c1c8620f20cb737a415160a1d307d93c
|
|
| BLAKE2b-256 |
d5772643607846fbdee6c1987c5a6aec9df2855b1c2247f4241319de3a436f6c
|