앞 세션 auto 커밋 cce57c298(Store_Logic 새 길 · /logic 답 머리만 · 판 = 문서 파일 지문 · 개정 = 문서 머리 대조 · 별칭 · 기계 등록 · [신규] · [삭제])에 이어 - Store_Cache: 막힘 세기(blocks · counted)를 문서 파일마다 · 저장 검사 logic_errors = 키 겹침 · 대장(요소 + 문서 키) · 연결 · 문서 막힘(check_logics 로직 줄 검사 걷음) · _docs_of = 문서 전부 · narrow 로직 갈래 걷음 · check_saved(부름 0) 지움 - Store_Save: 기초(로직 파일) 받지 않음(400) · gone · labor_errors(whole) 갈래 걷음 - Store_Logic: 정본 파일에도 새 기초(그 파일 표 키 — 옛 /save 와 같음) · 지움 검사에 조합 · 지운 기초를 부르던 문서 더함(옛 422 그대로) · 쓰는 곳 409 는 Doc.remove 로(옛 자리) - 시험(옛 /save 로 로직 줄 셈 칸 고침 · /logic 답 셈 칸을 붙든 것 = 죽은 길): 새 test_855_l3_doc_only(로직 파일 없음 + 같이 쓰기 끔 = 켬과 답 같음 · 목록 · 상세 · 저장 · 개정 409 · 판 409 · 별칭 · 신규 · 복사 · 삭제 · 기계 등록) · test_m01_cache 셈 칸 /save 검사 셋 · test_794_1 식 고침 /save 422 걷음(셈 칸 고침 = 문서 저장 몫 · /save 는 머리만 씀) · test_m01_make 「시험 계산에 돈다」 → 빈 문서로 열림 · test_m01_api · test_m01_text 옛 셈 길 시험은 로직 줄 사본에서 읽음 · test_854_2_m01_key_book 대장 끊김 = 인력 줄 + 기초 문서 쓰기 · test_794_1b · test_804_7 판 = 문서 파일 · test_802_3 문서 없는 키 = 404(빈 문서 안 지음) · test_826_2 좁힌 검사 = 판정만 견줌(기초 흠 글이 문서 꼴) · 로직 갈래 셋 뺌 · test_m01_copy 옛 시트 길 걷고 master_copy 왕복만 · test_854_2_m01_copy_doc 식 복사 → 기본정보 고친 복사 · test_713_1 · test_796_1 row_print 줄 뺌(row_print 지움) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
4.7 KiB
Python
107 lines
4.7 KiB
Python
"""713-1 지킴 — 로직 정본 줄 고침 · 지우기 · 더하기는 「원문 개정 반영」 확인(`개정확인`) 없이는 409 ·
|
||
요소 · 같은 줄 다시 보냄은 그대로 · 대조 = 문서 머리(855 L3 ⓐ). 임시 사본 폴더만 씀."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import shutil
|
||
|
||
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:
|
||
assert revise.is_canon("로직_산림품셈_09장_토공.json")
|
||
assert not revise.is_canon("로직_자체.json") and not revise.is_canon("인력.json")
|