Files
Aislo/resources/tester/test_713_1_revise.py
T
eomsangdonandClaude Opus 5.5 19640b3f89 refactor(855-E L2a): /logic 지문을 수식 문서 셈 칸 지문으로
- 옛 정본 줄 지문(Store_Revise.row_print · 로직 줄 셈 칸) → M02_Doc_Copy.doc_fp(수식 문서) · 읽는 화면 0
- 개정 확인 409(guard · changed)는 /save 가 로직 줄을 쓰는 동안 그대로(L3)
- test_713_1: 지문 시험을 문서 기준으로 — 비고 고침은 같음 · 문서 금액 줄 고침은 바뀜
- 라우터 쪽 시험 28 파일 267 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 02:17:30 +09:00

112 lines
5.0 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.
"""713-1 지킴 — 로직 정본 줄 고침 · 지우기 · 더하기는 「원문 개정 반영」 확인(`개정확인`) 없이는 409 ·
요소 · 같은 줄 다시 보냄은 그대로 · 줄 바탕 지문(`Store_Revise.row_print`). 임시 사본 폴더만 씀."""
from __future__ import annotations
import shutil
from decimal import Decimal
from pathlib import Path
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from M01_MasterData import M01_MasterData_Router as router_module
from M01_MasterData import M01_MasterData_Store as store
from M01_MasterData import M01_MasterData_Store_Revise as revise
REAL = store.FOLDER
KEY = "GC000091" # 공통 3-3-1 암발파 — 로직_건설품셈_03장_토공사.json
@pytest.fixture(scope="module")
def client(tmp_path_factory) -> TestClient:
folder = tmp_path_factory.mktemp("m01_revise")
for path in REAL.glob("*.json"):
if not path.name.startswith("_") or path.name == store.mk.BOOK.name:
shutil.copy(path, folder / path.name)
shutil.copytree(REAL / "기계", folder / "기계") # 기계 = 폴더(826-2)
patch = pytest.MonkeyPatch()
patch.setattr(store, "FOLDER", folder)
shutil.copytree(REAL / "수식문서", folder / "수식문서") # 로직 목록 = 수식 문서(855 L2 ⓐ)
patch.setattr(store._docs().ml, "FOLDER", folder / "수식문서")
app = FastAPI()
app.include_router(router_module.router)
yield TestClient(app)
patch.undo()
def _part(client: TestClient, op: str, row: dict | None = None, key: str | None = KEY) -> dict:
one = client.get("/api/m01/logic", params={"key": KEY}).json()
return {
"file": one["file"],
"version": one["version"],
"changes": [{"op": op, "key": key, "row": row}],
}
def _bytes(client: TestClient) -> bytes:
return (
store.FOLDER / client.get("/api/m01/logic", params={"key": KEY}).json()["file"]
).read_bytes()
def test_정본_고침_지움_더함_확인_없으면_409(client: TestClient) -> None:
base = client.get("/api/m01/logic", params={"key": KEY}).json()["logic"]
before = _bytes(client)
for op, row, key in (
("edit", {**base, "비고": "개정 시험"}, KEY),
("delete", None, KEY),
("add", {k: v for k, v in base.items() if k != "키"}, None),
):
res = client.post("/api/m01/save", json={"files": [_part(client, op, row, key)]})
assert res.status_code == 409, (op, res.text)
got = res.json()["detail"]
assert got["개정"][0]["op"] == op and "원문 개정 반영" in got["까닭"]
assert _bytes(client) == before # 확인 없이는 한 바이트도 안 바뀜
def test_같은_줄_다시_보냄은_그대로(client: TestClient) -> None:
base = client.get("/api/m01/logic", params={"key": KEY}).json()["logic"]
res = client.post("/api/m01/save", json={"files": [_part(client, "edit", base)]})
assert res.status_code == 200, res.text
def test_확인하면_저장_지문은_계산_칸만(client: TestClient) -> None:
"""`/logic` 지문 = 수식 문서 셈 칸 지문(855 L2 ⓐ) — 비고 고침은 그대로 · 문서 금액 줄 고침은 바뀜."""
from M02_MasterTemplete import M02_Doc_Copy as doc_copy
one = client.get("/api/m01/logic", params={"key": KEY}).json()
base, print0 = one["logic"], one["지문"]
doc = client.get("/api/m01/logic/doc", params={"key": KEY}).json()
assert print0 == doc_copy.doc_fp(doc["문서"])
body = {"files": [_part(client, "edit", {**base, "비고": "개정 시험"})], "개정확인": True}
assert client.post("/api/m01/save", json=body).status_code == 200
again = client.get("/api/m01/logic", params={"key": KEY}).json()
assert again["logic"]["비고"] == "개정 시험" and again["지문"] == print0 # 비고 = 지문 밖
doc = client.get("/api/m01/logic/doc", params={"key": KEY}).json()
line = doc["문서"]["금액"][0]
line["수량"] = f"({line['수량']}) × 2"
res = client.post("/api/m01/logic/doc/save", json={"문서": doc["문서"], "판": doc["판"]})
assert res.status_code == 200, res.text
assert client.get("/api/m01/logic", params={"key": KEY}).json()["지문"] != print0
def test_요소_파일은_대상_밖(client: TestClient) -> None:
rows = client.get("/api/m01/rows", params={"file": "인력.json", "size": 1}).json()
row = {**rows["rows"][0], "비고": "요소 시험"}
part = {
"file": "인력.json",
"version": rows["version"],
"changes": [{"op": "edit", "key": row["키"], "row": row}],
}
assert client.post("/api/m01/save", json={"files": [part]}).status_code == 200
def test_지문_수_꼴_같음() -> None:
a = {"이름": "가", "호표": [{"수량": Decimal("10.0")}], "끝수": 1}
b = {"이름": "나", "호표": [{"수량": 10}], "끝수": 1.0, "별칭": "x"}
assert revise.row_print(a) == revise.row_print(b)
assert revise.is_canon("로직_산림품셈_09장_토공.json")
assert not revise.is_canon("로직_자체.json") and not revise.is_canon("인력.json")