앞 세션 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.5 KiB
Python
107 lines
4.5 KiB
Python
"""M01 [로직 복사/생성] 이 수식 문서도 같이 지음(PLAN 854-2 · 요구 896) — 사본 폴더에서만.
|
|
|
|
- 만들면 문서 있음 · 새 계산기 금액 = 옛 엔진 = 본뜬 로직 · 빌더가 다시 지어도 같은 글.
|
|
- 지우면(`/logic/remove` · `/save` 지움) 문서도 없음 · [복사/생성] = 원본 문서 복제 + 기본정보(855 L3 ⓐ).
|
|
"""
|
|
|
|
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 = whole.logic(key) # 옛 로직 줄(같이 쓰기 · `/logic` 답은 머리만 · 855 L3 ⓐ)
|
|
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:
|
|
more = {"이름": "sub7임시 복사", "원문번호": "13-4-9", "결과단위": "m3", "출처": "자체 시험"}
|
|
made = _post(client, "/api/m01/logic/copy", {"key": SAMPLE, **more}) # 855 L3 ⓐ [복사/생성]
|
|
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)
|
|
head = _get(client, "/api/m01/logic", key=key)["logic"]
|
|
assert {k: head[k] for k in more} == more and head["키"] == 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()
|