2026-09-26 21:12:00 +00:00
|
|
|
|
"""card_status отчёта — статус карточки, активной у курсанта при завершении."""
|
|
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
from app.domain.events import Exercise, SessionMode
|
|
|
|
|
|
from app.domain.kio import KIO
|
|
|
|
|
|
from app.domain.statuses import CardStatus, ServiceStatus
|
|
|
|
|
|
from app.scenarios.loader import load_file
|
|
|
|
|
|
from app.session import finish as finish_module
|
|
|
|
|
|
from app.session.dds import prepare_handoff_queue, prepare_queue
|
|
|
|
|
|
from app.session.hub import hub
|
|
|
|
|
|
from app.session.state import SessionState
|
|
|
|
|
|
|
|
|
|
|
|
LIBRARY = Path(__file__).resolve().parents[2] / "scenarios"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
|
def offline_finish(monkeypatch):
|
|
|
|
|
|
class NoCoaching:
|
|
|
|
|
|
def model_dump(self, **_kwargs):
|
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
async def no_coach(_metrics):
|
|
|
|
|
|
return NoCoaching()
|
|
|
|
|
|
|
|
|
|
|
|
monkeypatch.setattr(finish_module, "coach", no_coach)
|
|
|
|
|
|
monkeypatch.setattr(hub, "journal", None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def accept_active_card(state: SessionState) -> None:
|
2026-09-26 21:38:09 +00:00
|
|
|
|
card = state.desk.active
|
|
|
|
|
|
service = card.dispatched_card.notify[0]
|
|
|
|
|
|
card.set_service_status(
|
2026-09-26 21:12:00 +00:00
|
|
|
|
service, ServiceStatus.ACCEPTED,
|
|
|
|
|
|
"Основание: доклад старшего.\nСведения: карточка принята.",
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def assert_active_card_kept(state: SessionState, active_id, active_status) -> None:
|
|
|
|
|
|
assert active_status is not CardStatus.REGISTERED
|
|
|
|
|
|
assert state.score["card_status"] == active_status.value
|
2026-09-26 21:38:09 +00:00
|
|
|
|
assert state.desk.active_id == active_id
|
2026-09-26 21:12:00 +00:00
|
|
|
|
assert len(state.score["card_results"]) == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_dds_finish_reports_status_of_active_card_not_last_scored():
|
|
|
|
|
|
first = load_file(LIBRARY / "fire-apartment-l2.yaml", LIBRARY)
|
|
|
|
|
|
second = load_file(LIBRARY / "tickets" / "t20-2-stroke.yaml", LIBRARY)
|
|
|
|
|
|
state = SessionState(
|
|
|
|
|
|
session_id=uuid4(), scenario_id=first.id, scenario_title=first.title,
|
|
|
|
|
|
level=first.level.value, mode=SessionMode.TRAINING, exercise=Exercise.DDS,
|
|
|
|
|
|
)
|
|
|
|
|
|
prepare_queue(state, [first, second])
|
2026-09-26 21:38:09 +00:00
|
|
|
|
assert len(state.desk.cards) == 2
|
|
|
|
|
|
active_id = state.desk.active_id
|
2026-09-26 21:12:00 +00:00
|
|
|
|
accept_active_card(state)
|
|
|
|
|
|
active_status = state.station_snapshot().card
|
|
|
|
|
|
|
|
|
|
|
|
asyncio.run(finish_module.finish(state.session_id, state))
|
|
|
|
|
|
|
|
|
|
|
|
assert_active_card_kept(state, active_id, active_status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_handoff_finish_reports_status_of_active_card_not_last_scored():
|
|
|
|
|
|
first = load_file(LIBRARY / "fire-apartment-l2.yaml", LIBRARY)
|
|
|
|
|
|
second = load_file(LIBRARY / "tickets" / "t01-1-fire-container.yaml", LIBRARY)
|
|
|
|
|
|
state = SessionState(
|
|
|
|
|
|
session_id=uuid4(), scenario_id=first.id, scenario_title=first.title,
|
|
|
|
|
|
level=first.level.value, mode=SessionMode.TRAINING,
|
|
|
|
|
|
exercise=Exercise.CARD, handoff_to_dds=True, scenario=first,
|
|
|
|
|
|
pending_dds_scenarios=[second],
|
|
|
|
|
|
)
|
|
|
|
|
|
state.kio = KIO(
|
|
|
|
|
|
address="улица Ленина, 14", description="горит балкон", notify=["Служба 101"],
|
|
|
|
|
|
)
|
|
|
|
|
|
state.dispatch()
|
|
|
|
|
|
prepare_handoff_queue(state, state.pending_dds_scenarios)
|
2026-09-26 21:38:09 +00:00
|
|
|
|
assert len(state.desk.cards) == 2
|
|
|
|
|
|
active_id = state.desk.active_id
|
2026-09-26 21:12:00 +00:00
|
|
|
|
accept_active_card(state)
|
|
|
|
|
|
active_status = state.station_snapshot().card
|
|
|
|
|
|
|
|
|
|
|
|
asyncio.run(finish_module.finish(state.session_id, state))
|
|
|
|
|
|
|
|
|
|
|
|
assert_active_card_kept(state, active_id, active_status)
|