Metadata-Version: 2.4
Name: flaxon-pytest
Version: 0.1.0
Summary: Pytest fixtures and utilities for testing Flaxon applications
Author-email: Aldane Hutchinson <aldanehutchinson5@gmail.com>
Maintainer-email: Aldane Hutchinson <aldanehutchinson5@gmail.com>
License: MIT
Project-URL: Homepage, https://flaxon-website.vercel.app/docs
Project-URL: Repository, https://github.com/aldanedev-create/flaxon-pytest.git
Project-URL: Bug_Tracker, https://github.com/aldanedev-create/flaxon-pytest.git
Keywords: flaxon,pytest,testing,fixtures,async,websocket
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pytest>=8.0.0
Requires-Dist: pytest-asyncio>=0.23.0
Requires-Dist: flaxon>=0.1.7
Dynamic: license-file

# flaxon-pytest

<p align="center">
  <img src="https://raw.githubusercontent.com/aldanedev-create/Flaxon-Backend-Framework/main/assets/flaxon.png" alt="flaxon Logo"
   width="200"/>
</p>

Pytest fixtures and utilities for testing Flaxon applications.

## Installation

```bash
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
