Implements all 88 tasks for the Reaction Image Board (specs/001-reaction-image-board): - docker-compose.yml: postgres, minio, minio-init, api, ui services with healthchecks - api/: FastAPI app with SQLAlchemy 2.x async, Alembic migrations, S3/MinIO storage, full integration + unit test suite (pytest + pytest-asyncio) - ui/: Angular 19 standalone app (Library, Upload, Detail, NotFound components) - .env.example: all required environment variables - .gitignore: Python, Node, Docker, IDE, .env patterns Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
import pytest
|
|
import pytest_asyncio
|
|
from httpx import AsyncClient, ASGITransport
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
|
|
|
from app.main import app
|
|
from app.config import get_settings
|
|
from app.database import Base
|
|
from app.dependencies import get_db, get_storage, get_auth
|
|
|
|
|
|
@pytest_asyncio.fixture(scope="session")
|
|
async def engine():
|
|
settings = get_settings()
|
|
# Use a separate test database URL if TEST_DATABASE_URL is set
|
|
import os
|
|
db_url = os.getenv("TEST_DATABASE_URL", settings.database_url)
|
|
eng = create_async_engine(db_url, echo=False)
|
|
async with eng.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield eng
|
|
async with eng.begin() as conn:
|
|
await conn.run_sync(Base.metadata.drop_all)
|
|
await eng.dispose()
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def db_session(engine):
|
|
session_factory = async_sessionmaker(engine, expire_on_commit=False)
|
|
async with session_factory() as session:
|
|
yield session
|
|
await session.rollback()
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def client(db_session):
|
|
from app.storage.s3_backend import S3StorageBackend
|
|
from app.auth.noop import NoOpAuthProvider
|
|
|
|
storage = S3StorageBackend()
|
|
auth = NoOpAuthProvider()
|
|
|
|
async def override_db():
|
|
yield db_session
|
|
|
|
def override_storage():
|
|
return storage
|
|
|
|
def override_auth():
|
|
return auth
|
|
|
|
app.dependency_overrides[get_db] = override_db
|
|
app.dependency_overrides[get_storage] = override_storage
|
|
app.dependency_overrides[get_auth] = override_auth
|
|
|
|
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as c:
|
|
yield c
|
|
|
|
app.dependency_overrides.clear()
|