Test utils
TestUtilsPlugin contributes no HTTP endpoints. Instead it exposes a
TestHelpers surface that test code retrieves from the plugin registry:
from pydantic import SecretStr
from fastauth import FastAuth, FastAuthOptions
from fastauth.database import memory
from fastauth.plugins.test_utils import TestUtilsOptions
from fastauth import email_password, test_utils
auth = FastAuth(
FastAuthOptions(
secret_key=SecretStr("replace-me-with-your-application-secret"),
database=memory(),
),
plugins=[email_password(), test_utils(TestUtilsOptions(capture_otp=True))],
)
helpers = auth.context.plugins.by_id["fastauth-test-utils"].helpers
Helper surface
helpers.create_user(**overrides)— build an unsavedUserwith sensible defaults.helpers.save_user(user)/helpers.delete_user(user_id)— go through the boundDatabaseAdapter.helpers.login(user_id)— create a session and return aLoginResultcontaining the plain token, prebuilt headers, and serialised cookies ready forhttpx.AsyncClient.helpers.get_auth_headers(user_id)— shortcut returning only the{"cookie": "..."}dict.helpers.get_otp(identifier)/helpers.clear_otps()— read or wipe the most recent captured one-time password (requirescapture_otp=True).