gendesign/backend/tests/services/test_planning_lookup.py
bot-backend ffab64aa6a
All checks were successful
CI / changes (push) Successful in 6s
CI / changes (pull_request) Successful in 5s
CI / backend-tests (push) Successful in 5m48s
CI / backend-tests (pull_request) Successful in 5m46s
feat(sf): wire ППТ/ПМТ planning_projects в analyze ird-блок (#1085)
2026-06-06 23:44:27 +03:00

58 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.

"""Тесты parcel_planning_overlaps (#1085 analyze-wiring) — ППТ/ПМТ overlap по участку.
БД не дёргается: фейковая сессия с .execute().mappings().all(). Проверяем graceful на
отсутствие участка/таблицы и проброс строк.
"""
from __future__ import annotations
from typing import Any
from sqlalchemy.exc import ProgrammingError
from app.services.site_finder.planning_lookup import parcel_planning_overlaps
class _Result:
def __init__(self, rows: list[dict[str, Any]]) -> None:
self._rows = rows
def mappings(self) -> _Result:
return self
def all(self) -> list[dict[str, Any]]:
return self._rows
class _DB:
def __init__(self, rows: list[dict[str, Any]] | Exception) -> None:
self._rows = rows
def execute(self, sql: Any, params: dict[str, Any]) -> _Result:
if isinstance(self._rows, Exception):
raise self._rows
return _Result(self._rows)
def test_returns_overlaps() -> None:
rows = [
{
"project_type": "ppt",
"doc_status_name": "действующий",
"full_name": "ПАГЕ №1",
"project_name": "Галактика",
"dmd_actual_year": 2021,
},
]
out = parcel_planning_overlaps(_DB(rows), "POINT(60 56)") # type: ignore[arg-type]
assert out == rows
def test_empty_wkt_returns_empty() -> None:
assert parcel_planning_overlaps(_DB([]), None) == [] # type: ignore[arg-type]
def test_missing_table_is_graceful() -> None:
"""planning_projects ещё не задеплоена → ProgrammingError → [] (analyze не падает)."""
db = _DB(ProgrammingError("stmt", {}, Exception("relation planning_projects does not exist")))
assert parcel_planning_overlaps(db, "POINT(60 56)") == [] # type: ignore[arg-type]