"""Presentation mode: fresh private demo patient straight into the chat; screening switch skips onboarding.""" from collections.abc import AsyncIterator import pytest from httpx import ASGITransport, AsyncClient from app.core import demo_settings from app.db import repo, session from app.db.bootstrap import init_db from app.integrations.emias_record import emias_records from app.main import app MEM = "sqlite+aiosqlite:///:memory:" @pytest.fixture async def client() -> AsyncIterator[AsyncClient]: await session.configure(identity_url=MEM, clinical_url=MEM) await init_db() async with AsyncClient(transport=ASGITransport(app=app), base_url="http://t") as c: yield c await session.configure() async def test_fresh_demo_patients_are_private_and_ready(client): a = (await client.post("/api/v1/auth/demo/fresh", json={})).json()["token"] b = (await client.post("/api/v1/auth/demo/fresh", json={})).json()["token"] assert a != b and a.startswith("tok-andrey-") async with session.get_clinical_session() as s: st = await repo.get_dialog_state(s, a) assert st.state == "idle" and st.data["consent"] is True rec = await emias_records.get(a) assert rec is not None and any("язвенная" in c.name.lower() for c in rec.conditions) r = await client.post(f"/api/v1/dialog/{a}/events", json={"type": "text", "text": "привет"}) assert r.status_code == 200 and r.json()["replies"] async def test_screening_switch(client): assert (await client.get("/api/v1/demo/settings")).json() == {"screening_enabled": True} assert (await client.post("/api/v1/demo/settings", json={"screening_enabled": False})).json() == { "screening_enabled": False } async with session.get_clinical_session() as s: assert await demo_settings.screening_enabled(s) is False