Skip to main content

Shared testing utilities and pytest fixtures for the Bloques ecosystem

Project description

ulfblk-testing

Shared testing utilities and pytest fixtures for the Bloques ecosystem.

Installation

# 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

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)

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)

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

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

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

ulfblk_testing-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

ulfblk_testing-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file ulfblk_testing-0.1.0.tar.gz.

File metadata

  • Download URL: ulfblk_testing-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ulfblk_testing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbc7a8d844abb3904b383232fe8b4b34571238bdab2db88f494bef6a7271c225
MD5 245d1d1af0f451f565f9610909b4b597
BLAKE2b-256 efc533be9c2531e02bd980f194bbcafc743997eaf334c1b64e95c9a7a9afa2b1

See more details on using hashes here.

File details

Details for the file ulfblk_testing-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ulfblk_testing-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ulfblk_testing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7f661e4ea0faad2f8b2291c4880cbfd52a10207cd508da770904cc934a3cc1a
MD5 dde3470ca41e9391ee9a19336b1f85b1
BLAKE2b-256 878004d0fc0c7514573404289c4c23d641ea5296355df4f1ebef8153922ed286

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