Files
kiskaadee 285add0b98 feat(api): implement sculptures read router with spatial coordinate serialization
- Add GET /sculptures and GET /sculptures/{id} endpoints

- Implement EWKB/WKT coordinate extractor for PostGIS geometry

- Register router in FastAPI application

- Configure NullPool test database fixture to prevent connection pool clashes

- Add comprehensive integration and unit test suite (31 tests passing)

- Update todo.txt milestone tracking
2026-10-13 08:09:08 -05:00

47 lines
1.2 KiB
Python

from collections.abc import AsyncGenerator
import pytest
from httpx import ASGITransport, AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.pool import NullPool
from api.core.config import settings
from api.database.session import get_db_session
from api.main import app
# Engine with NullPool prevents cross-loop asyncpg connection clashes in pytest
test_engine = create_async_engine(
settings.DATABASE_URL,
poolclass=NullPool,
echo=False,
)
TestAsyncSessionLocal = async_sessionmaker(
bind=test_engine,
class_=AsyncSession,
expire_on_commit=False,
autocommit=False,
autoflush=False,
)
async def override_get_db_session() -> AsyncGenerator[AsyncSession, None]:
async with TestAsyncSessionLocal() as session:
try:
yield session
finally:
await session.close()
app.dependency_overrides[get_db_session] = override_get_db_session
@pytest.fixture
async def async_client() -> AsyncGenerator[AsyncClient, None]:
"""
Test client for FastAPI ASGI endpoints.
"""
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client