- FastAPI app with lifespan, CORS, health endpoint - SQLAlchemy 2.0 async with aiosqlite, Base/UUIDMixin/TenantMixin/TimestampMixin - Tenant and User models with multi-tenant isolation - Auth: register (creates tenant+user), login, /me endpoint - JWT HS256 tokens, bcrypt password hashing - Alembic async setup with initial migration - 6 passing tests (register, login, wrong password, me, no token, health) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
717 B
Python
25 lines
717 B
Python
import pytest
|
|
import pytest_asyncio
|
|
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
|
|
|
from app.db.base import Base
|
|
from app.db.session import get_db
|
|
from app.main import app
|
|
|
|
|
|
@pytest_asyncio.fixture(autouse=True)
|
|
async def setup_test_db():
|
|
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
session_factory = async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
async def override_db():
|
|
async with session_factory() as s:
|
|
yield s
|
|
|
|
app.dependency_overrides[get_db] = override_db
|
|
yield
|
|
app.dependency_overrides.clear()
|
|
await engine.dispose()
|