gendesign/backend/tests/services/test_planning_lookup.py
lekss361 53e76738b4
All checks were successful
Deploy / changes (push) Successful in 6s
Deploy / build-worker (push) Successful in 2m26s
Deploy / build-frontend (push) Has been skipped
Deploy / build-backend (push) Successful in 1m22s
Deploy / deploy (push) Successful in 1m14s
feat(sf): wire ППТ/ПМТ planning_projects в analyze ird-блок (#1105)
planning_lookup.py (parcel_planning_overlaps, ST_Intersects через GIST idx_planning_projects_geom) + ird_analyze.py ключ planning_projects (DB-only). ППТ/ПМТ overlap участка в analyze ird-блоке. За флагом enable_ird_analyze (OFF), parcels.py не тронут. Зеркалит ird_overlay_lookup. Зависит от #1104 (м.134). 7 тестов.

Refs #1085.
Co-authored-by: lekss361 <lekss361@gendsgn.local>
Co-committed-by: lekss361 <lekss361@gendsgn.local>
2026-06-06 20:50:34 +00: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]