"""Demo mode (crisis_blocking off): a crisis signal inside a questionnaire does not stop it; the crisis message comes at the end and blocks nothing; the weapon question triggers nothing.""" import pytest from app.db.clinical import Alert from tests.test_dialog_intake import answer_button, complete_existing, press, released, rows # noqa: F401 @pytest.fixture def non_blocking(monkeypatch): from app.config import get_settings monkeypatch.setattr(get_settings(), "crisis_blocking", False) async def test_red_flag_does_not_stop_the_questionnaire(released, non_blocking): # noqa: F811 replies = await press(released, "intake:start") replies = await press(released, answer_button(replies, {"rf_psychosis": 0})) # «Да» on a red flag assert not any(r.kind == "crisis" for r in replies), "no crisis window in the middle of the test" assert any(r.buttons for r in replies), "the next question is asked" (row,) = await rows() assert row.status != "interrupted" and row.details["pending_urgent"]["code"] == "red_flag_psychosis" replies = await complete_existing(released, replies, {}) assert any(r.kind == "crisis" for r in replies), "the crisis message comes at the end" assert any(a.code == "red_flag_psychosis" and a.level == "acute" for a in await rows(Alert)) async def test_weapon_answer_triggers_nothing(released, non_blocking): # noqa: F811 replies = await press(released, "intake:start") for _ in range(2): # psychosis, harm to others: «Нет» replies = await press(released, answer_button(replies)) replies = await press(released, answer_button(replies, {"rf_weapons": 0})) # «Да» on weapons assert not any(r.kind == "crisis" for r in replies) (row,) = await rows() assert not row.details.get("pending_urgent")