DFiP_Budget_planing/api/tests/unit/test_summary2_log_privacy.py
Andrey Epifancev 782a04381b Правки финального ревью фазы 1: M-1, M-2, M-5
- M-1: поиск по перекрытым полям contract_summary (ооо лютик, дс-2, дс-1) и неперекрытому (70), явные assert для строки 910004
- M-2: в лог db_time вместо значений поиска и фильтров пишутся признаки has_*/search_len; unit-тест на caplog
- M-5: total читается по имени столбца total_count

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 22:12:14 +04:00

61 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Лог 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)