- All business models: Vehicle, Order, OrderLine, Invoice, Appointment, CatalogMarca/Model/Ansamblu/Norma/Pret/TipDeviz/TipMotor, Mecanic - Sync endpoints: GET /sync/full, GET /sync/changes?since=, POST /sync/push with tenant isolation and last-write-wins conflict resolution - Order CRUD with state machine: DRAFT -> VALIDAT -> FACTURAT Auto-recalculates totals (manopera + materiale) - Vehicle CRUD: list, create, get, update - Seed data: 24 marci, 11 ansamble, 6 tipuri deviz, 5 tipuri motoare, 3 preturi - Alembic migration for all business models - 13 passing tests (auth + sync + orders) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
import pytest
|
|
import pytest_asyncio
|
|
from httpx import ASGITransport, AsyncClient
|
|
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()
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def client():
|
|
async with AsyncClient(
|
|
transport=ASGITransport(app=app), base_url="http://test"
|
|
) as c:
|
|
yield c
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def auth_headers(client):
|
|
r = await client.post(
|
|
"/api/auth/register",
|
|
json={
|
|
"email": "test@service.ro",
|
|
"password": "testpass123",
|
|
"tenant_name": "Test Service",
|
|
"telefon": "0722000000",
|
|
},
|
|
)
|
|
token = r.json()["access_token"]
|
|
return {"Authorization": f"Bearer {token}"}
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def tenant_id(client):
|
|
r = await client.post(
|
|
"/api/auth/register",
|
|
json={
|
|
"email": "tenant@service.ro",
|
|
"password": "testpass123",
|
|
"tenant_name": "Tenant Service",
|
|
"telefon": "0722000001",
|
|
},
|
|
)
|
|
return r.json()["tenant_id"]
|