Объединяет наше (площади из реальной геометрии teap) + полноту девелоперской Excel-модели (каскад затрат + БДР с налогами). Расширяет financial.py из статического GDV−COST в полный статический расчёт. БЕЗ DCF (PR-3), БЕЗ новых вводных от пользователя — только нормативы + существующий TEAP. Каскад (financial.py): - Выручка: жильё (residential×price) + ПАРКИНГ (spaces×1.9М) - Затраты: СМР(резид+паркинг) + ПИР 2.5% + сети/ТУ 6000₽/м² + услуги заказчика 1.5% + резерв 3% + маркетинг/риэлтор 7% выручки + земля - БДР: валовая маржа → НДС (упрощённо) → прибыль до налога → налог 25% (ФЗ 176-ФЗ) → ЧИСТАЯ прибыль → ROI + чистая маржа% - Нормативы документированы (источник: Excel-эталон «Авангардная 13» + RU-рынок) FinancialModel (concept.py): +16 additive-полей (revenue breakdown, cost cascade, БДР/налоги, roi, margin_pct, irr_is_proxy). Старые 4 поля сохранены (backward-compat). IRR честно помечен irr_is_proxy=True (annualized net ROI, не DCF) — настоящий IRR/NPV/PBP в PR-3 (помесячный cashflow). НДС — документированное упрощение, не точный НК РФ. Офисы пропущены (нет площади в TEAP). PDF + concept UI: полный БДР-каскад + чистая прибыль/ROI + честные сноски. api-types.ts регенерён авторитетно (openapi-typescript + prettier, как CI). mypy strict clean (generative.*), +тесты (каскад/паркинг/налоги/backward-compat/ edge cost=0), 36 passed. Refs #1881
136 lines
3.8 KiB
Python
136 lines
3.8 KiB
Python
"""End-to-end API test — POST /api/v1/concepts returns 3 filled variants.
|
|
|
|
Goes through the FastAPI route (TestClient) and asserts the contract is populated
|
|
with *real* numbers (non-zero ТЭП + financial), valid building GeoJSON, and that a
|
|
degenerate parcel yields 422 rather than empty variants.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
|
|
_PARCEL = {
|
|
"type": "Polygon",
|
|
"coordinates": [
|
|
[
|
|
[60.60, 56.830],
|
|
[60.6045, 56.830],
|
|
[60.6045, 56.8328],
|
|
[60.60, 56.8328],
|
|
[60.60, 56.830],
|
|
]
|
|
],
|
|
}
|
|
|
|
|
|
def _post(payload: dict[str, object]) -> object:
|
|
client = TestClient(app)
|
|
return client.post("/api/v1/concepts", json=payload)
|
|
|
|
|
|
def test_concepts_returns_three_filled_variants() -> None:
|
|
response = _post(
|
|
{
|
|
"parcel_geojson": _PARCEL,
|
|
"housing_class": "comfort",
|
|
"target_floors": 9,
|
|
"development_type": "mid_rise",
|
|
"land_cost_rub": 150_000_000,
|
|
}
|
|
)
|
|
assert response.status_code == 200, response.text
|
|
variants = response.json()["variants"]
|
|
assert len(variants) == 3
|
|
assert {v["strategy"] for v in variants} == {"max_area", "max_insolation", "balanced"}
|
|
|
|
for v in variants:
|
|
teap = v["teap"]
|
|
fin = v["financial"]
|
|
# Реальные, ненулевые числа (не stub-нули).
|
|
assert teap["built_area_sqm"] > 0
|
|
assert teap["total_floor_area_sqm"] > 0
|
|
assert teap["residential_area_sqm"] > 0
|
|
assert teap["apartments_count"] > 0
|
|
assert teap["density"] > 0
|
|
assert teap["parking_spaces"] > 0
|
|
assert fin["revenue_rub"] > 0
|
|
assert fin["cost_rub"] > 0
|
|
# GeoJSON застройки непустой.
|
|
fc = v["buildings_geojson"]
|
|
assert fc["type"] == "FeatureCollection"
|
|
assert len(fc["features"]) > 0
|
|
|
|
|
|
def test_concepts_degenerate_parcel_returns_422() -> None:
|
|
tiny = {
|
|
"type": "Polygon",
|
|
"coordinates": [
|
|
[
|
|
[60.60, 56.830],
|
|
[60.60015, 56.830],
|
|
[60.60015, 56.83015],
|
|
[60.60, 56.83015],
|
|
[60.60, 56.830],
|
|
]
|
|
],
|
|
}
|
|
response = _post(
|
|
{
|
|
"parcel_geojson": tiny,
|
|
"housing_class": "comfort",
|
|
"target_floors": 9,
|
|
"development_type": "mid_rise",
|
|
}
|
|
)
|
|
assert response.status_code == 422
|
|
|
|
|
|
def test_concepts_response_matches_contract_keys() -> None:
|
|
response = _post(
|
|
{
|
|
"parcel_geojson": _PARCEL,
|
|
"housing_class": "business",
|
|
"target_floors": 16,
|
|
"development_type": "high_rise",
|
|
}
|
|
)
|
|
assert response.status_code == 200
|
|
variant = response.json()["variants"][0]
|
|
assert set(variant.keys()) == {"strategy", "buildings_geojson", "teap", "financial"}
|
|
assert set(variant["teap"].keys()) == {
|
|
"built_area_sqm",
|
|
"total_floor_area_sqm",
|
|
"residential_area_sqm",
|
|
"apartments_count",
|
|
"density",
|
|
"parking_spaces",
|
|
}
|
|
assert set(variant["financial"].keys()) == {
|
|
# legacy summary (backward-compat)
|
|
"revenue_rub",
|
|
"cost_rub",
|
|
"gross_margin_rub",
|
|
"irr",
|
|
# revenue breakdown
|
|
"revenue_residential_rub",
|
|
"revenue_parking_rub",
|
|
# cost cascade
|
|
"construction_rub",
|
|
"pir_rub",
|
|
"networks_rub",
|
|
"developer_services_rub",
|
|
"contingency_rub",
|
|
"marketing_rub",
|
|
"land_rub",
|
|
# БДР / taxes
|
|
"vat_rub",
|
|
"profit_before_tax_rub",
|
|
"profit_tax_rub",
|
|
"net_profit_rub",
|
|
# metrics
|
|
"roi",
|
|
"margin_pct",
|
|
"irr_is_proxy",
|
|
}
|