- D02 정본 칸 plan_base_json = {epsg, starts: [{x, y}], ends: [...]} · 옛 start · end 는 읽을 때 목록으로 감쌈(옮김 없음)
- 목록마다 상한 20 · 저장된 epsg 가 있으면 그대로(점이 늘어 평균 경도가 띠를 넘어도 D03 노선과 안 어긋남)
- 부르는 곳 없던 연도 잇기 코드(chain_years · with_tm · changed · _store) 걷음 — 시험도 지움
- D03 지형 입구 = 시점 · 종점 모두 · 정본 굳힘 = 새 꼴
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
"""D 지형 API(PLAN 530-1 · 561-2) — 범위 = 전체 시점 · 종점(D02 정본) 상자 + 여유 · 받기 = 한 벌.
|
|
|
|
옛 분석 API 시험(GET · PUT analysis · 꺾임점 고침)은 옛 추천 엔진과 함께 걷음(PLAN 562-2) ·
|
|
노선 정본 시험 = `test_530_2_plan_analyze.py` · 지형 셈 시험 = `test_530_1_plan_terrain.py`.
|
|
|
|
./venv/Scripts/python.exe -m pytest resources/tester/test_530_2_plan_router.py -q
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
from contextlib import asynccontextmanager
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from D03_PlanAnalysis import D03_PlanAnalysis_Router as router_mod
|
|
|
|
PID = "12953f5a-5ba1-42ad-a427-8ac857a58bc2"
|
|
P0, P2 = (0.0, 0.0), (900.0, 400.0)
|
|
URL = f"/api/projects/{PID}/plan/terrain"
|
|
|
|
|
|
class _Pool:
|
|
@asynccontextmanager
|
|
async def acquire(self):
|
|
yield None
|
|
|
|
|
|
@pytest.fixture
|
|
def client(tmp_path, monkeypatch):
|
|
plan = {
|
|
"epsg": 5186,
|
|
"starts": [{"lon": 0, "lat": 0, "x": P0[0], "y": P0[1]}],
|
|
"ends": [{"lon": 0, "lat": 0, "x": P2[0], "y": P2[1]}],
|
|
}
|
|
|
|
async def load_base(project_id):
|
|
return plan
|
|
|
|
async def stored(connection, project_id):
|
|
return "1/3/p"
|
|
|
|
monkeypatch.setattr(router_mod.base, "load_base", load_base)
|
|
monkeypatch.setattr(router_mod, "get_db_pool", lambda: _Pool())
|
|
monkeypatch.setattr(router_mod, "get_project_storage_relative_path", stored)
|
|
monkeypatch.setattr(router_mod, "resolve_stored_project_path", lambda s: str(tmp_path))
|
|
app = FastAPI()
|
|
app.include_router(router_mod.router)
|
|
test = TestClient(app)
|
|
test.plan = plan
|
|
return test
|
|
|
|
|
|
def test_extent_uses_whole_ends(client) -> None:
|
|
got = client.get(f"{URL}/extent?margin_m=400").json()
|
|
m = 400.0
|
|
assert got["margin_m"] == m and got["have"] is None and got["covered"] is False
|
|
# 전체 시점 · 종점(D02 정본) — 연도 구간 아님
|
|
assert got["box_m"] == [P0[0] - m, P0[1] - m, P2[0] + m, P2[1] + m]
|
|
extra = client.get(f"{URL}/extent", params={"extra": json.dumps([[2000, 0]])}).json()
|
|
assert extra["box_m"][2] == 2000 + extra["margin_m"]
|
|
assert client.get(f"{URL}/extent", params={"extra": "[1]"}).status_code == 400
|
|
client.plan["ends"] = [] # 종점 빔 — 1단계로
|
|
assert client.get(f"{URL}/extent").status_code == 400
|
|
|
|
|
|
def test_post_runs_one_set(client, monkeypatch) -> None:
|
|
calls: list = []
|
|
saved: list = []
|
|
works: list = []
|
|
|
|
def ensure(root, points, epsg, margin_m, report):
|
|
calls.append((points, epsg, margin_m))
|
|
return {"sheets": {"downloaded": ["1"]}, "models": [{"model_file_path": "m"}]}
|
|
|
|
async def save(project_id, models, epsg):
|
|
saved.append((models, epsg))
|
|
|
|
def start(project_id, kind, work):
|
|
works.append(work)
|
|
return {"status": "accepted", "kind": kind}
|
|
|
|
def post(body):
|
|
res = client.post(URL, json=body)
|
|
asyncio.run(works.pop()(lambda percent, message: None))
|
|
return res
|
|
|
|
monkeypatch.setattr(router_mod.terrain, "ensure_plan_terrain", ensure)
|
|
monkeypatch.setattr(router_mod, "_save_models", save)
|
|
monkeypatch.setattr(router_mod, "_start_job", start)
|
|
res = post({"margin_m": 500, "extra": [[5, 6]]})
|
|
assert res.json() == {"status": "accepted", "kind": "terrain"}
|
|
assert calls == [([P0, P2, (5.0, 6.0)], 5186, 500.0)]
|
|
assert saved == [([{"model_file_path": "m"}], 5186)]
|
|
# 옛 화면 꼴(points 몸) — 여유 처음 값 · 전체 시점 · 종점
|
|
post({"points": []})
|
|
assert calls[-1] == ([P0, P2], 5186, None)
|