55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""Integration tests: model surface, ai_log_job translation fan-out,
|
|
route-level localized fetch, settings PATCH validation."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
def _build_session_factory(tmp_path):
|
|
"""Per-test sqlite engine + factory. Mirrors test_referral_conversion.py."""
|
|
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
|
|
|
from app import db as db_mod
|
|
from app.db import Base
|
|
import app.models # noqa: F401 — registers models on Base.metadata
|
|
|
|
engine = create_async_engine(f"sqlite+aiosqlite:///{tmp_path}/loc.db")
|
|
factory = async_sessionmaker(engine, expire_on_commit=False)
|
|
db_mod._engine = engine
|
|
db_mod._session_factory = factory
|
|
|
|
async def _setup():
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
return engine, factory, _setup
|
|
|
|
|
|
def test_user_has_lang_column_with_default_en():
|
|
from sqlalchemy import inspect
|
|
from app.models import User
|
|
|
|
cols = {c.name: c for c in inspect(User).columns}
|
|
assert "lang" in cols
|
|
assert cols["lang"].nullable is False
|
|
# SQLAlchemy default may be a callable or a literal — check both.
|
|
default = cols["lang"].default
|
|
assert default is not None
|
|
if hasattr(default, "arg"):
|
|
assert default.arg == "en"
|
|
|
|
|
|
def test_strategic_log_translation_model_columns():
|
|
from sqlalchemy import inspect
|
|
from app.models import StrategicLogTranslation
|
|
|
|
cols = {c.name: c for c in inspect(StrategicLogTranslation).columns}
|
|
assert "log_id" in cols
|
|
assert "lang" in cols
|
|
assert "content_md" in cols
|
|
assert "generated_at" in cols
|
|
assert "llm_model" in cols
|
|
assert "llm_cost_usd" in cols
|
|
assert cols["log_id"].nullable is False
|
|
assert cols["lang"].nullable is False
|
|
assert cols["content_md"].nullable is False
|