async def lds_status_in_journal(ws_client, cfg: LDSStatusConfig, test_data: CaseData):
"""
Проверка наличия записи в журнале о выходе СОУ из режима Инициализация.
"""
# Распаковка данных для теста
control_points = test_data.params.get("control_points")
if isinstance(test_data.expected_result, tuple):
expected_lds_status, expected_lds_status_reasons = test_data.expected_result
else:
expected_lds_status, expected_lds_status_reasons = test_data.expected_result, None
with allure.step("Запрос сообщений журнала с фильтром messageTypes=LDS_STATUS"):
end_time = datetime.now()
start_time = t_utils.datetime_minus_seconds(end_time, TestConst.JOURNAL_STATUS_TOTAL_WAIT)
request_body = t_utils.create_journal_req_body(
pagination=Pagination(limit=TestConst.JOURNAL_PAGINATION_STATUS_LIMIT, direction=Direction.FIRST.value),
filtering=Filtering(messageTypes=int(MessageType.LDS_STATUS), objects=FilteringObjects(tuId=cfg.tu_id)),
)
payload = await t_utils.connect_and_get_msg(ws_client, "GetMessagesRequest", request_body)
parsed_payload = parser.parse_journal_msg(payload)
with allure.step("Извлечение и подготовка данных для проверки"):
messages_info = getattr(parsed_payload.replyContent, 'messagesInfo', [])
StepCheck("Проверка наличия сообщений в журнале", "messagesInfo").actual(messages_info).is_not_empty()
with allure.step("Фильтрация сообщений по времени и controlPoint"):
filter_start_msk = t_utils.localize_as_moscow(start_time)
filter_end_msk = t_utils.localize_as_moscow(end_time)
lds_msg_by_control_points = []
time_filtered = [
msg
for msg in messages_info
if filter_start_msk <= t_utils.ensure_moscow_timezone(msg.time) <= filter_end_msk
]
time_filtered.sort(key=lambda msg: t_utils.ensure_moscow_timezone(msg.time), reverse=True)
# Поиск нужных сообщений по КП
for control_point in control_points:
lds_msg = next(
(msg for msg in time_filtered if msg.controlPoint == control_point),
None,
)
lds_msg_by_control_points.append(lds_msg)
StepCheck(
f"Проверка наличия сообщений c controlPoint из списка {control_points} в журнале", "messagesInfo"
).actual(lds_msg_by_control_points).is_not_empty()
with SoftAssertions() as soft_failures:
for msg in lds_msg_by_control_points:
msg_event = getattr(msg, 'event', None)
cp_lds_status, cp_lds_status_reasons = t_utils.parse_event(msg_event)
StepCheck(f"Проверка режима работы СОУ на КП:{msg.controlPoint}", "event", soft_failures).actual(
cp_lds_status
).expected(expected_lds_status).equal_to()
if cp_lds_status != LdsStatus.SERVICEABLE.report_text:
StepCheck(
"Проверка причины режима работы СОУ на КП:{msg.controlPoint}", "event", soft_failures
).contains(cp_lds_status_reasons, expected_lds_status_reasons)