models: add User.lang + StrategicLogTranslation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
7683f82820
commit
9423fa81b7
2 changed files with 93 additions and 0 deletions
55
tests/test_localization_integration.py
Normal file
55
tests/test_localization_integration.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""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
|
||||
Loading…
Add table
Add a link
Reference in a new issue