diff --git a/B09_Estimation/draft/B09_Draft_Print_Drawings_Source.py b/B09_Estimation/draft/B09_Draft_Print_Drawings_Source.py index b3bc11872..2d05d08b7 100644 --- a/B09_Estimation/draft/B09_Draft_Print_Drawings_Source.py +++ b/B09_Estimation/draft/B09_Draft_Print_Drawings_Source.py @@ -11,6 +11,7 @@ B07 화면과 같은 TS 를 Node 로(`B09_Draft_Print_Drawings_Node.ts` · CLAUD from __future__ import annotations import asyncio +import json import logging import subprocess from pathlib import Path @@ -76,9 +77,12 @@ async def b07_drawing(project_id: UUID, drawing_id: str) -> dict[str, Any]: from B07_DesignDetail.B07_DesignDetail_Router import get_design_drawing response = await get_design_drawing(project_id, drawing_id) - if not hasattr(response, "drawing"): - raise ValueError(f"B07 도면 「{drawing_id}」 을 읽지 못했습니다.") - return response.model_dump() + if hasattr(response, "drawing"): + return response.model_dump() + # 계획평면도 파생 저장본(508-3c) = 그린 응답 JSON 그대로(Response) — 오류 JSONResponse 와 구별 + if getattr(response, "status_code", None) == 200 and response.media_type == "application/json": + return json.loads(response.body) + raise ValueError(f"B07 도면 「{drawing_id}」 을 읽지 못했습니다.") async def section_detail(project_id: UUID, route_id: int) -> dict[str, Any] | None: diff --git a/resources/tester/test_543_print_plan_stored_copy.py b/resources/tester/test_543_print_plan_stored_copy.py new file mode 100644 index 000000000..c9a4d02ea --- /dev/null +++ b/resources/tester/test_543_print_plan_stored_copy.py @@ -0,0 +1,35 @@ +"""B09 인쇄 도면 — B07 계획평면도 파생 저장본(Response JSON 그대로)도 읽음 · 오류 응답은 400 글.""" + +from __future__ import annotations + +import asyncio +import json +from uuid import uuid4 + +import pytest +from fastapi import Response +from fastapi.responses import JSONResponse + +from B07_DesignDetail import B07_DesignDetail_Router as b07 +from B09_Estimation.draft import B09_Draft_Print_Drawings_Source as source + +DRAWING = {"entities": [{"type": "Line"}], "layers": []} + + +def _read(monkeypatch, response): + async def fake(project_id, drawing_id): + return response + + monkeypatch.setattr(b07, "get_design_drawing", fake) + return asyncio.run(source.b07_drawing(uuid4(), "plan_terrain")) + + +def test_저장본_Response_JSON_을_읽음(monkeypatch): + body = json.dumps({"id": "plan_terrain", "drawing": DRAWING, "confirmed": False}) + got = _read(monkeypatch, Response(content=body.encode(), media_type="application/json")) + assert got["drawing"] == DRAWING and got["confirmed"] is False + + +def test_오류_응답은_읽지_못함(monkeypatch): + with pytest.raises(ValueError, match="plan_terrain"): + _read(monkeypatch, JSONResponse(status_code=404, content={"message": "없음"}))