- Store_Logic: WRITE · CALC · mirror · _ordered · _headed_row · _picks · _write 지움(로직 JSON 쓰는 곳 0) - Machine.register 의 mirror 줄 · Store_Save._logic_file · Store_Cache 「!= 로직」 표지 걷음 · labor_errors = 있는 기초 키(수식 문서)만(whole.logic 갈래 지움) - M01 Doc: _row · sync_tags · ensure · built · of_row · make 지움 · 읽기 「층바탕」(빌더 문서) 뺌 · 손고침 = 셈 칸을 고친 적 있는 기초(저장 전 문서와 다르면 붙음 · 한 번 붙으면 남음 · 브레인 정함) - M02 Doc_Sk.base_doc · Doc_Sk_Path 층바탕의 빌더 문서 갈래 지움(그 자리 = 지금 문서) - 화면 LogicRow 셈 칸 · [신규] 빈 셈 칸 · 안 쓰는 꼴 셋 지움 - 시험: 855_l3_doc_only = 옛 로직 파일 놓여도 안 읽고 안 씀 · 848_1 손고침 표지 · 848_10 빌더 층 시험 지움 · 파일만 복사한 프로젝트 층(바탕문서 없음) = 지금 문서를 따라감 · 854_2 복사 = 원본 문서 금액(옛 엔진 대조 뺌) · 848_5 · 855_l1 로직 줄 대조 뺌 · labor_errors 손님 셋 = 있는 키 묶음 - 서버 답 243 건 다름 0 · typecheck 0 · 관련 105 파일(717_2a 원래 실패 · 792_3 엔진 몸 일감 몫 빼고) 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.7 KiB
Python
92 lines
3.7 KiB
Python
"""M01 [로직 복사/생성] 이 수식 문서도 같이 지음(PLAN 854-2 · 요구 896) — 사본 폴더에서만.
|
|
|
|
- 만들면 문서 있음 · 금액 = 본뜬 기초 문서 금액.
|
|
- 지우면(`/logic/remove` · `/save` 지움) 문서도 없음 · [복사/생성] = 원본 문서 복제 + 기본정보(855 L3 ⓐ).
|
|
"""
|
|
|
|
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_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 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["셈"]) == _money(source["셈"]) and _money(source["셈"])["계"] > 0
|
|
|
|
# 지우면 문서도 같이
|
|
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()
|
|
source = _money(_get(client, "/api/m01/logic/doc", key=SAMPLE)["셈"])
|
|
assert _money(_get(client, "/api/m01/logic/doc", key=key)["셈"]) == source
|
|
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()
|