Files
Aislo/resources/tester/test_794_1_m01_sheet.py
T
eomsangdonandClaude Opus 5.5 c88ba7890a refactor(855-E 2-E1): M01 옛 셈 길 /calc · /text 걷음(M02 감싼 길 포함)
- 길 넷 걷음: POST /api/m01/calc · /text · /api/m02/logic-lib/calc · /text — 화면 부름 0(9c7807297 에 runCalc · runText 걷음) · 다른 서버 모듈 · B08 · B09 부름 0 · /openapi.json 480 → 476(이 넷만 빠짐)
- 본체 걷음: Store.calc · text · _swap · DRAFT · Store_Sheet.py(옛 /text 계산서 덧칸) · Router.CalcBody · _pct
- 남김: Store.mtx(B09 Sangeun_Text · M02 Logic_Settle 가 씀) · Store._logic_files(M02 Item_Source · Logic_Standard)
- 시험: 옛 엔진(B09 · M02 가 아직 씀)을 이 길 꼴로 보던 시험 11 파일은 새 도우미 helper_855_old_engine_routes(같은 몸 · 시험 전용 · 2-E4 에서 엔진과 같이 지움)를 앱에 붙임 · M01 시험 계산 길만 보던 test_149_4 한 시험 · test_717_1 M02 /calc 시험 지움
- 관련 1,158(1,105 + 다시 돈 실패 파일 151) 통과 · 빌더 --check 같음 · typecheck 0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 04:32:15 +09:00

93 lines
4.2 KiB
Python

# ruff: noqa: E501
"""794-1 M01 로직 줄 식 고침 저장 — `/save`(개정 확인) 뒤 다시 셈 · 틀린 식 422 · 시스템 관리자만.
- 시트 서버 길(`/logic/sheet` · `/check`)은 화면 0 이라 853-1 에 걷음 — 남은 것은 살아 있는 `/save` · `/calc`
- 서버(사본 폴더): 공구손료 식 1 → 2 % 저장(개정 확인 409 → 200) 뒤 셈 51,802 · 틀린 식 저장 422 · 시스템 관리자가 아니면 403
"""
from __future__ import annotations
import copy
import hashlib
import shutil
from pathlib import Path
import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from common_util.common_util_auth import require_system_admin, verify_session
from M01_MasterData import M01_MasterData_Router as m01_router
from M01_MasterData import M01_MasterData_Store as store
import helper_855_old_engine_routes as old_engine # noqa: E402 — 옛 셈 길 몸(855 2-E1 · 시험 전용)
REAL = store.FOLDER
KEY = "GC000211" # 합판거푸집 설치 및 해체
INPUTS = {"자재지역": "포항", "유형": "보통", "사용횟수": "6회", "높이감률": 0, "지붕슬래브": "아님",
"폼타이": "아님", "폼타이규격": "12.7㎜", "측압": "3t/㎡", "구멍땜": 0} # fmt: skip
TOOL_1 = "(형틀목공 * LB000007 + 보통인부 * LB000002) * 1 / 100" # 덧줄 첫 줄 엔진 식
TOOL_2 = TOOL_1.replace("* 1 / 100", "* 2 / 100")
def _hashes(folder: Path) -> dict[str, str]:
return {p.name: hashlib.md5(p.read_bytes()).hexdigest() for p in sorted(folder.glob("*.json"))}
# ── 서버 ─────────────────────────────────────────────────────────────
@pytest.fixture
def folder(tmp_path: Path, monkeypatch) -> Path:
master = tmp_path / "master"
master.mkdir()
for path in REAL.glob("*.json"):
shutil.copy(path, master / path.name)
shutil.copytree(REAL / "기계", master / "기계") # 기계 = 폴더(826-2)
monkeypatch.setattr(store, "FOLDER", master)
return master
@pytest.fixture
def client(folder: Path) -> TestClient:
app = FastAPI()
app.include_router(m01_router.router)
app.include_router(old_engine.router)
return TestClient(app)
def _post(client: TestClient, url: str, body: dict, want: int = 200) -> dict:
res = client.post(url, json=body)
assert res.status_code == want, res.text
return res.json()
def test_저장_길_개정_확인_다시_셈_틀린_식_422(client: TestClient, folder: Path) -> None:
real = _hashes(REAL)
one = client.get("/api/m01/logic", params={"key": KEY}).json()
row = copy.deepcopy(one["logic"])
assert row["덧줄"][0]["식"] == TOOL_1
row["덧줄"][0]["식"] = TOOL_2
body = {"files": [{"file": one["file"], "version": one["version"],
"changes": [{"op": "edit", "key": KEY, "row": row}]}]} # fmt: skip
assert client.post("/api/m01/save", json=body).status_code == 409 # 정본 = 개정 확인
_post(client, "/api/m01/save", {**body, "개정확인": True})
saved = client.get("/api/m01/logic", params={"key": KEY}).json()
assert saved["logic"]["덧줄"][0]["식"] == TOOL_2
sums = _post(client, "/api/m01/calc", {"key": KEY, "inputs": INPUTS})["sums"]
assert sums["계"] == 51802 and sums["경비"] == 765 # _분석_650-H2 4 장 공구손료 2 %
bad = copy.deepcopy(saved["logic"])
bad["덧줄"][0]["식"] = "형틀목공 * 없는이름"
body = {"files": [{"file": saved["file"], "version": saved["version"],
"changes": [{"op": "edit", "key": KEY, "row": bad}]}], "개정확인": True} # fmt: skip
before = _hashes(folder)
assert client.post("/api/m01/save", json=body).status_code == 422
assert _hashes(folder) == before and _hashes(REAL) == real
def test_시스템_관리자가_아니면_403(folder: Path) -> None:
app = FastAPI()
app.include_router(
m01_router.router, dependencies=[Depends(verify_session), Depends(require_system_admin)]
)
app.dependency_overrides[verify_session] = lambda: {"role": "USER", "company_id": 1}
client = TestClient(app)
assert client.post("/api/m01/save", json={"files": []}).status_code == 403