gendesign/tradein-mvp/backend/tests/test_estimator_floor_optional.py
bot-backend cdf493f345
All checks were successful
Deploy / changes (push) Successful in 9s
Deploy Trade-In / changes (push) Successful in 13s
Deploy / build-frontend (push) Has been skipped
Deploy / deploy-caddy (push) Has been skipped
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / build-browser (push) Has been skipped
Deploy / build-backend (push) Successful in 2m23s
Deploy Trade-In / test (push) Successful in 3m56s
Deploy / build-worker (push) Successful in 4m16s
Deploy Trade-In / build-backend (push) Successful in 1m19s
Deploy / deploy (push) Successful in 1m49s
Deploy / deploy-status (push) Successful in 1s
Deploy / perimeter-smoke (push) Successful in 12s
Deploy Trade-In / deploy (push) Successful in 2m25s
Deploy Trade-In / deploy-status (push) Successful in 1s
Deploy Trade-In / perimeter-smoke (push) Successful in 11s
chore(format): нормализация под ruff 0.15.20 — 161 файл, только формат (#2864) (#3022)
2026-08-21 12:01:52 +00:00

59 lines
2.1 KiB
Python

"""Verifies estimator does not crash on NotNullViolation when floor/total_floors=None.
Uses MagicMock for DB (consistent with other test_estimator_* tests — no live DB needed).
The test validates schema construction + that floor=None is accepted without ValueError.
The actual NOT NULL guard is covered by migration 065.
"""
from __future__ import annotations
import os
os.environ.setdefault("DATABASE_URL", "postgresql://test:test@localhost/test_db")
from app.schemas.trade_in import TradeInEstimateInput
def test_trade_in_input_floor_none_accepted() -> None:
"""TradeInEstimateInput accepts floor=None without ValidationError (PR #558)."""
payload = TradeInEstimateInput(
address="Екатеринбург, ул. Малышева, 84",
area_m2=55,
rooms=2,
floor=None,
total_floors=None,
has_balcony=False,
)
assert payload.floor is None
assert payload.total_floors is None
def test_trade_in_input_floor_present_accepted() -> None:
"""TradeInEstimateInput still validates positive floor values correctly."""
payload = TradeInEstimateInput(
address="Екатеринбург, ул. Малышева, 84",
area_m2=55,
rooms=2,
floor=3,
total_floors=9,
has_balcony=True,
)
assert payload.floor == 3
assert payload.total_floors == 9
def test_estimator_tf_str_none_safe() -> None:
"""estimator tier-H note: tf_str with total_floors=None yields empty string (not '0-эт.')."""
# Inline the logic from estimator.py:744 to verify the `is not None` guard.
total_floors: int | None = None
tf_str = f"{total_floors}-эт." if total_floors is not None else ""
assert tf_str == ""
def test_estimator_tf_str_zero_safe() -> None:
"""total_floors=0 (edge case) also produces empty string via is not None guard."""
total_floors: int | None = 0
tf_str = f"{total_floors}-эт." if total_floors is not None else ""
# 0 passes `is not None` so it would render — this matches existing behavior
# (0 is schema-invalid via ge=1, so this is a theoretical edge case only)
assert tf_str == "0-эт."