- 양식 장의 식 칸을 화면에서 고치면 같은 풀이기(TS)로 왕복 없이 즉시 다시 풂 - [식 저장]은 식만 보내고 서버가 Node 로 다시 푼 값을 돌려줌 — 브라우저 값을 받아 적지 않음 - 고친 식은 프로젝트 장 단위(산출 조건 structure_formula_overrides) · 양식 식과 같거나 비면 지움 - 원단위·자재총괄·인계·유토 입력(build_table)도 같은 고친 식을 봄 · 고친 줄 출처 user(「사용자 식」) - 틀린 식도 막지 않고 저장하되 줄마다 오류를 돌려줌 · 양식에 없는 줄 차례는 400 - 개인 라이브러리 저장 단추는 4장(라이브러리 저장소) 몫으로 남김 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016VBGFXB9AbJBwXP19z75Qq
209 lines
8.8 KiB
Python
209 lines
8.8 KiB
Python
"""구조물도 창구(B08) — B07 에서 옮긴 뒤 조회·제원 저장이 한 벌로 도는지 (2026-09-13, PLAN 3장 ②).
|
|
|
|
겨누는 것 셋
|
|
① 조회가 장을 냄 — 옛 B07 `/standard-sheets` 자리
|
|
② ⚠ 기초잡석 두께가 **산출 조건 값을 따름** — 옛 B07 창구는 두께를 안 넘겨 늘 0.2 로 섰음
|
|
(원단위 탭과 구조물도가 같은 구조물에서 다른 값을 냈음)
|
|
③ 제원 저장이 그 장의 개소에 걸리고, 다시 조회하면 새 제원으로 섬
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
import B08_Quantity.B08_Quantity_Router_Material as material_module # noqa: E402
|
|
import B08_Quantity.B08_Quantity_Router_StructureSheet as router_module # noqa: E402
|
|
from B05_Profile.B05_Profile_Structures_Repository import save_structures # noqa: E402
|
|
from B05_Profile.B05_Profile_Structures_Schema import StructureInstance # noqa: E402
|
|
|
|
PROJECT_ID = "22222222-2222-2222-2222-222222222222"
|
|
SHEETS = f"/api/projects/{PROJECT_ID}/quantity/structure-sheets"
|
|
|
|
|
|
@pytest.fixture()
|
|
def project(tmp_path: Path) -> Path:
|
|
root = tmp_path / "project"
|
|
root.mkdir()
|
|
wall = StructureInstance.model_validate(
|
|
{
|
|
"type_id": "masonry_wet",
|
|
"placement": "interval",
|
|
"start_m": 100.0,
|
|
"end_m": 110.0,
|
|
"options": {"height_m": 2.5, "back_len_cm": 45},
|
|
}
|
|
)
|
|
save_structures(str(root), [wall], base_revision=0)
|
|
return root
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(project: Path, monkeypatch: pytest.MonkeyPatch) -> TestClient:
|
|
async def fake_root(project_id):
|
|
return str(project)
|
|
|
|
async def no_route(project_id):
|
|
return {}
|
|
|
|
monkeypatch.setattr(router_module, "_project_root", fake_root)
|
|
monkeypatch.setattr(material_module, "_section_modes", no_route)
|
|
monkeypatch.setattr(material_module, "_ground_types", no_route)
|
|
app = FastAPI()
|
|
app.include_router(router_module.router)
|
|
return TestClient(app)
|
|
|
|
|
|
def _sheet(client: TestClient) -> dict:
|
|
response = client.get(SHEETS)
|
|
assert response.status_code == 200, response.text
|
|
sheets = response.json()["sheets"]
|
|
assert len(sheets) == 1, sheets
|
|
return sheets[0]
|
|
|
|
|
|
def _unit_amount(sheet: dict, name: str) -> float:
|
|
return next(row["unit_amount"] for row in sheet["rows"] if row["name"] == name)
|
|
|
|
|
|
def test_조회가_장을_낸다(client: TestClient) -> None:
|
|
sheet = _sheet(client)
|
|
assert sheet["type_id"] == "masonry_wet"
|
|
assert sheet["member_count"] == 1
|
|
assert sheet["billing_unit"] == "m" and sheet["billing_total"] == pytest.approx(10.0)
|
|
assert all("spec" in row for row in sheet["rows"])
|
|
|
|
|
|
def test_양식이_있는_종류는_줄마다_식을_싣는다(client: TestClient) -> None:
|
|
"""PLAN 3장 ④ · 명세 13장 — 찰쌓기는 양식으로 줄이 서고 식·설명·갈 곳·출처가 실림."""
|
|
sheet = _sheet(client)
|
|
assert sheet["library_item"]["type_id"] == "masonry_wet"
|
|
rows = {row["name"]: row for row in sheet["rows"]}
|
|
돌쌓기 = rows["돌쌓기"]
|
|
assert 돌쌓기["formula"] == "H*L*SQRT(1+N^2)"
|
|
assert "비탈면적" in 돌쌓기["basis"]
|
|
assert 돌쌓기["source"] == "library" and 돌쌓기["destination"] == "unit_price"
|
|
assert all(row["destination"] for row in sheet["rows"]) # 갈 곳 빈 줄 없음
|
|
# 돌 줄은 이름 고정 — 종류를 안 골라 규격이 빔(매칭 성공 아님, 명세 13장 Ⓒ).
|
|
assert rows["돌"]["spec"] == ""
|
|
# m당 값 — 제원(H=2.5·뒷길이 45·1:0.3)으로 다시 셈한 값.
|
|
assert 돌쌓기["unit_amount"] == pytest.approx(2.5 * (1 + 0.3**2) ** 0.5)
|
|
|
|
|
|
def test_안_선_줄은_안_섬으로_실린다(client: TestClient) -> None:
|
|
"""버림을 「안 넣음」으로 저장하면 버림·기초잡석이 0 이 아니라 「안 섬」으로 옴."""
|
|
sheet = _sheet(client)
|
|
saved = client.put(
|
|
f"{SHEETS}/spec",
|
|
json={"sheet_key": sheet["key"], "base_revision": 1, "blinding_concrete": "안 넣음"},
|
|
)
|
|
assert saved.status_code == 200, saved.text
|
|
rows = {row["name"]: row for row in _sheet(client)["rows"]}
|
|
for name in ("버림콘크리트", "기초잡석"):
|
|
assert rows[name]["skipped"] is True and rows[name]["unit_amount"] is None, rows[name]
|
|
assert rows[name]["reason"], rows[name]
|
|
|
|
|
|
def test_식을_고쳐_저장하면_서버가_다시_풀고_되돌릴_수_있다(
|
|
client: TestClient, project: Path
|
|
) -> None:
|
|
"""PLAN 3장 ⑤ — 프로젝트 장 단위 저장 · 값은 서버가 다시 냄 · 고친 줄은 출처 user."""
|
|
sheet = _sheet(client)
|
|
rows = {row["name"]: row for row in sheet["rows"]}
|
|
원래 = rows["모르터"]
|
|
saved = client.put(
|
|
f"{SHEETS}/formulas",
|
|
json={"sheet_key": sheet["key"], "rows": [{"seq": 원래["no"], "formula": "A*0.018"}]},
|
|
)
|
|
assert saved.status_code == 200, saved.text
|
|
assert saved.json()["changed"] == 1 and saved.json()["errors"] == []
|
|
|
|
after = {row["name"]: row for row in _sheet(client)["rows"]}
|
|
assert after["모르터"]["unit_amount"] == pytest.approx(원래["unit_amount"] * 2)
|
|
assert after["모르터"]["source"] == "user"
|
|
assert after["모르터"]["default_formula"] == 원래["formula"]
|
|
assert after["돌쌓기"]["source"] == "library" # 안 고친 줄은 그대로 양식
|
|
stored = json.loads((project / "project_settings.json").read_text(encoding="utf-8"))
|
|
assert stored["quantity"]["structure_formula_overrides"][sheet["key"]] == {
|
|
str(원래["no"]): {"formula": "A*0.018"}
|
|
}
|
|
|
|
# 원단위·자재총괄(build_table)도 같은 고친 식을 봄 — 구조물도와 안 갈림.
|
|
from B08_Quantity.B08_Quantity_Engine_UnitQuantity import build_table
|
|
from B08_Quantity.B08_Quantity_Router_Material import _collect_structures
|
|
|
|
structures, names, _ = _collect_structures(str(project))
|
|
table = build_table(
|
|
structures,
|
|
names,
|
|
None,
|
|
None,
|
|
None,
|
|
structure_formulas=stored["quantity"]["structure_formula_overrides"],
|
|
)
|
|
mortar = next(c for c in table["structures"][0]["components"] if c["name"] == "모르터")
|
|
assert mortar["amount"] == pytest.approx(after["모르터"]["unit_amount"] * 10.0)
|
|
assert mortar["source"] == "user" and "사용자 식" in mortar["basis"]
|
|
|
|
# 되돌리기 — 빈 식이면 양식 식으로, 저장 칸에서도 지워짐.
|
|
reverted = client.put(
|
|
f"{SHEETS}/formulas",
|
|
json={"sheet_key": sheet["key"], "rows": [{"seq": 원래["no"], "formula": None}]},
|
|
)
|
|
assert reverted.status_code == 200 and reverted.json()["changed"] == 1
|
|
back = {row["name"]: row for row in _sheet(client)["rows"]}
|
|
assert back["모르터"]["unit_amount"] == pytest.approx(원래["unit_amount"])
|
|
assert back["모르터"]["source"] == "library"
|
|
stored = json.loads((project / "project_settings.json").read_text(encoding="utf-8"))
|
|
assert stored["quantity"]["structure_formula_overrides"] == {}
|
|
|
|
|
|
def test_틀린_식도_막지_않고_저장하되_오류를_돌려준다(client: TestClient) -> None:
|
|
sheet = _sheet(client)
|
|
seq = next(row["no"] for row in sheet["rows"] if row["name"] == "모르터")
|
|
saved = client.put(
|
|
f"{SHEETS}/formulas",
|
|
json={"sheet_key": sheet["key"], "rows": [{"seq": seq, "formula": "A*없는칸"}]},
|
|
)
|
|
assert saved.status_code == 200, saved.text
|
|
assert any("모르터" in error and "모르는 이름" in error for error in saved.json()["errors"])
|
|
bad = client.put(
|
|
f"{SHEETS}/formulas",
|
|
json={"sheet_key": sheet["key"], "rows": [{"seq": 999, "formula": "1"}]},
|
|
)
|
|
assert bad.status_code == 400
|
|
|
|
|
|
def test_기초잡석_두께가_산출_조건을_따른다(client: TestClient, project: Path) -> None:
|
|
기본 = _unit_amount(_sheet(client), "기초잡석")
|
|
(project / "project_settings.json").write_text(
|
|
json.dumps({"quantity": {"rubble_base_thickness_m": 0.3}}), encoding="utf-8"
|
|
)
|
|
바꿈 = _unit_amount(_sheet(client), "기초잡석")
|
|
# 기본 0.2 → 0.3 — 버림 폭에 두께 비를 곱하는 식이라 1.5 배.
|
|
assert 바꿈 == pytest.approx(기본 * 1.5)
|
|
|
|
|
|
def test_제원_저장이_그_장에_걸린다(client: TestClient) -> None:
|
|
sheet = _sheet(client)
|
|
saved = client.put(
|
|
f"{SHEETS}/spec",
|
|
json={"sheet_key": sheet["key"], "base_revision": 1, "back_len_cm": "55"},
|
|
)
|
|
assert saved.status_code == 200, saved.text
|
|
assert saved.json()["changed"] == 1
|
|
assert _sheet(client)["options"]["back_len_cm"] == 55
|
|
|
|
|
|
def test_없는_장이면_404(client: TestClient) -> None:
|
|
response = client.put(f"{SHEETS}/spec", json={"sheet_key": "없는 장", "base_revision": 1})
|
|
assert response.status_code == 404
|