Metadata-Version: 2.4
Name: ulfblk-testing
Version: 0.1.0
Summary: Shared testing utilities and pytest fixtures for the Bloques ecosystem
Project-URL: Homepage, https://github.com/abelardodiaz/web25-991-bloques-reciclables
Project-URL: Documentation, https://github.com/abelardodiaz/web25-991-bloques-reciclables/tree/main/packages/python/ulfblk-testing
Project-URL: Repository, https://github.com/abelardodiaz/web25-991-bloques-reciclables
Project-URL: Issues, https://github.com/abelardodiaz/web25-991-bloques-reciclables/issues
Author-email: Abelardo Diaz <abelardo@bloques.dev>
License-Expression: MIT
Keywords: bloques,fastapi,fixtures,pytest,testing
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
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 :: Libraries
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: fastapi>=0.115.0
Requires-Dist: httpx>=0.27
Requires-Dist: pytest>=8.0
Provides-Extra: all
Requires-Dist: aiosqlite>=0.20; extra == 'all'
Requires-Dist: cryptography>=42.0; extra == 'all'
Requires-Dist: pyjwt[crypto]>=2.8; extra == 'all'
Requires-Dist: sqlalchemy[asyncio]>=2.0; extra == 'all'
Provides-Extra: auth
Requires-Dist: cryptography>=42.0; extra == 'auth'
Requires-Dist: pyjwt[crypto]>=2.8; extra == 'auth'
Provides-Extra: db
Requires-Dist: aiosqlite>=0.20; extra == 'db'
Requires-Dist: sqlalchemy[asyncio]>=2.0; extra == 'db'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: ulfblk-auth; extra == 'dev'
Requires-Dist: ulfblk-core; extra == 'dev'
Requires-Dist: ulfblk-db; extra == 'dev'
Description-Content-Type: text/markdown

# ulfblk-testing

Shared testing utilities and pytest fixtures for the Bloques ecosystem.

## Installation

```bash
# Base (HTTP client factories + settings helpers)
uv add --dev ulfblk-testing

# With JWT auth fixtures
uv add --dev "ulfblk-testing[auth]"

# With database fixtures
uv add --dev "ulfblk-testing[db]"

# Everything
uv add --dev "ulfblk-testing[all]"
```

## Auto-registered Fixtures (pytest plugin)

When installed, these fixtures are automatically available in your tests:

| Fixture | Requires | Scope | Description |
|---------|----------|-------|-------------|
| `test_app` | base | function | Minimal FastAPI app with `/ping` endpoint |
| `test_client` | base | function | AsyncClient bound to `test_app` |
| `rsa_keys` | `[auth]` | session | RSA key pair `(private_pem, public_pem)` |
| `jwt_manager` | `[auth]` | function | `JWTManager` with test RSA keys |
| `test_engine` | `[db]` | function | SQLite in-memory AsyncEngine |
| `test_session_factory` | `[db]` | function | `async_sessionmaker` bound to engine |

## Helper Functions

### HTTP Clients

```python
from ulfblk_testing import create_test_client, create_authenticated_client

# Basic client
async with create_test_client(app) as client:
    resp = await client.get("/health")

# Authenticated client
token = create_test_token(jwt_manager)
async with create_authenticated_client(app, token) as client:
    resp = await client.get("/protected")
```

### JWT Auth (`[auth]` extra)

```python
from ulfblk_testing import generate_rsa_keys, create_jwt_manager, create_test_token

# Generate keys + manager
private_pem, public_pem = generate_rsa_keys()
manager = create_jwt_manager(private_pem, public_pem)

# Or auto-generate keys
manager = create_jwt_manager()

# Create test tokens with defaults
token = create_test_token(manager, user_id="u-1", tenant_id="t-1", roles=["admin"])
```

### Database (`[db]` extra)

```python
from ulfblk_testing import create_test_engine, create_test_session_factory, create_tables

engine = create_test_engine()
session_factory = create_test_session_factory(engine)
await create_tables(engine, Base)

async with session_factory() as session:
    # your test queries
    pass
```

### Settings

```python
from ulfblk_testing import create_test_settings, override_settings
from ulfblk_core import BloqueSettings

# Create settings with overrides
settings = create_test_settings(BloqueSettings, debug=True)

# Temporarily patch a settings object
with override_settings("myapp.config.settings", BloqueSettings, debug=True):
    # settings patched here
    pass
```
