Skip to main content

Pytest fixtures and utilities for testing Flaxon applications

Project description

flaxon-pytest

flaxon Logo

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


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.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flaxon_pytest-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file flaxon_pytest-0.1.1.tar.gz.

File metadata

  • Download URL: flaxon_pytest-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for flaxon_pytest-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c9d05c1814b232443281c575e99bb375fe3a045634e6eda9e27d98dc38ac1b70
MD5 32af89ee28eeeaff001ab02fba835468
BLAKE2b-256 74940876081db287a706c3360b32c8dad4b1ba068c6ab434c47487850e5837d6

See more details on using hashes here.

File details

Details for the file flaxon_pytest-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flaxon_pytest-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for flaxon_pytest-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e0766538d92214590f4caa01610135afbd9065881930b91870091cc05d54687
MD5 84c8e16e4e6ab8c513552b140c0a92a1
BLAKE2b-256 1722b78e59956d7c47c22ec8ded44df5f7cfa1067b29887f3fbfb8d9ab4f8ae4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page