gendesign/tradein-mvp/backend/tests/services/test_estimator_precision.py
Light1YT 492dd0aba6 feat(tradein): бейдж точности адреса (qc_geo) на карточке оценки (accuracy #1)
Честность к пользователю: показываем насколько точно определён адрес —
«до дома» / «до улицы» / «приблизительно» — рядом с confidence.

- schemas/trade_in.py: address_precision: Literal["house","street","approximate"]|None
- estimator.py: _qc_geo_to_precision (qc_geo 0→house, 1→street, ≥2→approximate,
  None→None), set в основном return + _empty_estimate
- api/v1/trade_in.py: get_estimate + estimate_pdf теперь rehydrate'ят DaData-поля
  (canonical_address, house_cadnum, house_fias_id, address_precision, metro_nearest)
  из row — раньше на ?id= reopen / в PDF вся Q1-обогащёнка пропадала (поймал
  code-reviewer). Колонки уже persisted, фикс read-path.
- frontend: AddressPrecision type + precision-badge в HeroSummary (.card-meta),
  токены --success/--accent-2/--bg-card-alt, без новых токенов.

Канон: tech-analyst (план) → backend-engineer + frontend-engineer → code-reviewer
( APPROVE, поймал reopen-path gap) → fold-in fix. Tests: 7 passed, tsc clean, ruff clean.
match_house_readonly wiring отложен (fast-follow).
2026-05-28 15:37:33 +05:00

43 lines
1.3 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.

"""Unit tests for `app.services.estimator._qc_geo_to_precision`.
Pure-function mapping DaData qc_geo → address-precision indicator:
- 0 → "house" (дом распознан точно)
- 1 → "street" (до улицы)
- 2/3/4/5 → "approximate" (населённый пункт / город / регион / не распознан)
- None → None (DaData не отрабатывала)
Чистый unit-тест: без БД и сети.
"""
from __future__ import annotations
import os
import sys
from unittest.mock import MagicMock
import pytest
# DATABASE_URL required by config before any app import (см. test_dadata.py).
os.environ.setdefault("DATABASE_URL", "postgresql+psycopg://test:test@localhost:5432/test")
# WeasyPrint stub — not installed in CI без GTK (consistent с test_dadata.py).
_wp_mock = MagicMock()
sys.modules.setdefault("weasyprint", _wp_mock)
from app.services.estimator import _qc_geo_to_precision # noqa: E402
@pytest.mark.parametrize(
("qc_geo", "expected"),
[
(0, "house"),
(1, "street"),
(2, "approximate"),
(3, "approximate"),
(4, "approximate"),
(5, "approximate"),
(None, None),
],
)
def test_qc_geo_to_precision(qc_geo: int | None, expected: str | None) -> None:
assert _qc_geo_to_precision(qc_geo) == expected