"""Лог db_time не содержит значений поиска и фильтров (только признаки).""" import logging from types import SimpleNamespace import pytest from fastapi import Response from src.api.v1 import summary as summary_api SECRET = "СЕКРЕТНЫЙ-ПОИСК-123" FILTERS = {"smeta_type": "СЕКРЕТ-ТИП", "smeta_direction": "СЕКРЕТ-НАПР", "org_name": "СЕКРЕТ-ОРГ"} class _FakeService: def __init__(self, db): pass async def get_svod2_page(self, **kwargs): return [], 0 async def get_svod2_facets(self, **kwargs): return {} @pytest.fixture(autouse=True) def _fake_service(monkeypatch): monkeypatch.setattr(summary_api, "SummaryService", _FakeService) monkeypatch.setattr(summary_api, "Svod2Facets", lambda **kw: kw, raising=False) def _assert_no_values(caplog): records = [r for r in caplog.records if getattr(r, "type", None) == "db_time"] assert records for r in records: text = r.getMessage() + repr(r.__dict__) for value in (SECRET, *FILTERS.values()): assert value not in text assert r.has_search is True assert r.search_len == len(SECRET) assert r.has_smeta_type and r.has_smeta_direction and r.has_org_name @pytest.mark.asyncio async def test_page_log_has_no_search_values(caplog): caplog.set_level(logging.INFO) await summary_api.get_summary2( sheet="GO", year=2031, response=Response(), search=SECRET, db=None, current_user=SimpleNamespace(id=1), view="compact", **FILTERS, ) _assert_no_values(caplog) @pytest.mark.asyncio async def test_facets_log_has_no_search_values(caplog): caplog.set_level(logging.INFO) await summary_api.get_summary2_facets( sheet="GO", year=2031, response=Response(), search=SECRET, db=None, current_user=SimpleNamespace(id=1), **FILTERS, ) _assert_no_values(caplog)