Files
Aislo/resources/tester/test_854_2_m01_copy_doc.py
T
eomsangdonandClaude Opus 5.5 7d19c0389d feat(854-2): M01 [로직 복사/생성] 이 수식 문서를 같이 지음 · 로직 지우면 문서도 — 묶음 ③
- Doc.make = 빌더와 같은 변환(convert) · 같은 대조(옛 엔진 = 새 계산기 · 기본 + 옵션 표본 · 부르는 단가산출 저장본)를 지난 것만 수식_<파일>.json 에 씀(빌더가 다시 지어도 같은 글) · 못 지나면 안 씀
- Store_Make.logic_new(/logic/copy · /logic/formula/save 공용)가 make 부름 · 답에 「수식문서」
- Store_Make.save 의 로직 줄 지움(/save)도 그 수식 문서를 지움(/logic/remove 와 같은 끝 · 문서만 남지 않게)
- 빌더 build_수식문서_802_2 = 대조 갈래 cases_of · agree 로 꺼냄(동작 같음 · --check 같음)
- 시험 test_854_2_m01_copy_doc — 복사 · 식 복사 → 문서 있음 · 금액 = 옛 엔진 = 본뜬 로직 · 빌더 다시 지음 = 같은 파일 글 · 지움 → 문서 없음

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

109 lines
4.3 KiB
Python

"""M01 [로직 복사/생성] 이 수식 문서도 같이 지음(PLAN 854-2 · 요구 896) — 사본 폴더에서만.
- 만들면 문서 있음 · 새 계산기 금액 = 옛 엔진 = 본뜬 로직 · 빌더가 다시 지어도 같은 글.
- 지우면(`/logic/remove` · `/save` 지움) 문서도 없음.
"""
from __future__ import annotations
import importlib
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_Doc as doc_screen
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_Make as make
REAL = store.FOLDER
SAMPLE = "GF000219" # 산림 13-4-1 메쌓기(인력)
COSTS = ("노무비", "재료비", "경비", "계")
@pytest.fixture
def client(tmp_path: Path, monkeypatch) -> TestClient:
for path in REAL.glob("*.json"):
if not path.name.startswith("_") or path.name == store.mk.BOOK.name:
shutil.copy(path, tmp_path / path.name)
shutil.copytree(REAL / "기계", tmp_path / "기계")
shutil.copytree(REAL / "수식문서", tmp_path / "수식문서")
monkeypatch.setattr(store, "FOLDER", tmp_path)
monkeypatch.setattr(doc_screen.ml, "FOLDER", tmp_path / "수식문서")
doc_screen._memo.clear()
app = FastAPI()
app.include_router(router_module.router)
return TestClient(app)
def _get(client: TestClient, url: str, **params) -> dict:
res = client.get(url, params=params)
assert res.status_code == 200, res.text
return res.json()
def _post(client: TestClient, url: str, body: dict) -> dict:
res = client.post(url, json=body)
assert res.status_code == 200, res.text
return res.json()
def _money(answer: dict) -> dict:
return {k: Decimal(str(answer[k])) for k in COSTS}
def _old(key: str) -> dict:
"""옛 엔진 금액(빌더 대조와 같은 길 · 기본 입력)."""
builder = importlib.import_module("build_수식문서_802_2")
whole = store.loaded()[1]
row = store.logic(key)["logic"]
return _money(builder.old_answer(whole, row, builder.cases_of(whole, row)[0][1]))
def test_복사로_만든_로직은_수식_문서가_있고_금액이_옛_엔진과_같다(client: TestClient) -> None:
made = _post(client, "/api/m01/logic/copy", {"key": SAMPLE, "이름": "sub5임시 본뜸"})
key = made["key"]
assert key.startswith("GX") and made["수식문서"] is True
got = _get(client, "/api/m01/logic/doc", key=key)
assert got["새"] is False and got["파일"] == "수식_자체.json" and got["문서"]["식"]
assert got["셈"]["셈됨"] is True
source = _get(client, "/api/m01/logic/doc", key=SAMPLE)
assert _money(got["셈"]) == _old(key) == _money(source["셈"]) and _old(key)["계"] > 0
# 빌더가 다음에 다시 지어도 같은 파일 글(옛 로직 줄이 있는 키 = 빌더 몫)
builder = importlib.import_module("build_수식문서_802_2")
result = builder.build(log=lambda *_: None)
assert key in result["저장"]
want = builder.files_of(result)["수식_자체.json"]
assert (doc_screen.folder() / "수식_자체.json").read_text(encoding="utf-8") == want
# 지우면 문서도 같이
info = _get(client, "/api/m01/logic", key=key)
_post(
client,
"/api/m01/logic/remove",
{"key": key, "file": info["file"], "version": info["version"]},
)
assert _get(client, "/api/m01/logic/doc", key=SAMPLE)["새"] is False
assert key not in doc_screen.docs()
def test_식_복사로_만든_로직도_문서가_있고_save_지움이면_문서도_없다(client: TestClient) -> None:
view = _get(client, "/api/m01/logic/formula", key=SAMPLE)
made = _post(
client,
"/api/m01/logic/formula/save",
{"로직": view["로직"], "별칭": view["별칭"], "본뜬키": SAMPLE, "이름": "sub5임시 식복사"},
)
key = made["key"]
assert made["수식문서"] is True and key in doc_screen.docs()
assert _money(_get(client, "/api/m01/logic/doc", key=key)["셈"]) == _old(key)
body = {"file": make.OWN, "version": made["version"], "changes": [{"op": "delete", "key": key}]}
_post(client, "/api/m01/save", {"files": [body]})
assert key not in doc_screen.docs()