Files
Aislo/resources/tester/test_840_4_my_material.py
T
eomsangdonandClaude Opus 5.5 0291a19347 refactor(858 5-8 ①): 서고 감쌈 걷음 — 부르는 쪽이 한 벌을 바로 부름
- 쓰는 곳: `Labor_Ref.refuse_used` 감쌈 지움 → Router_Layers · Store.delete 가 `Library_Uses.refuse_used` · `MyMachine._uses` · `Material_Own.uses` 지움 → `Library_Uses.machines` · `materials`
- 권한: `Library_Delete.can_write` 별칭 · `Library_Same_Router._can_write` 지움 → `Layer_Access.can_write`
- 층 폴더: `MyMachine_Router._folder` 감쌈 지움 → `Router_Items._root(…, personal=MINE)`(MyMachine_Look 도)
- 화면: Material_Pick `OwnRow` 지움 → 내 재료 Api `MyMaterial` 꼴
- 시험: 797_1 · 840_4 · 821_1 · 733_3 · 735_1 이 감쌈 대신 한 벌을 부름 · 갈아 끼움(monkeypatch)은 `access.can_write`

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

80 lines
4.0 KiB
Python

# ruff: noqa: F811 — 임시 층 fixture(world)를 test_m02_labor_ref 에서 받아 씀
"""840-4 내 재료(개인 자재 PM) = M01 재료 DB 에 없는 자재 등록 자리 — 임시 storage.
① M01 재료 DB 와 이름 · 규격 · 단위가 같으면 만들기 · 고치기 막음(409) · 품명 · 단위 빈 = 400
② 단가산출 재료 줄이 내 재료를 M01 재료처럼 읽음(미리 셈 · 저장)
③ 내 재료 값을 고치면 개인 층 단가산출 금액이 따라옴(836-2 자동 따라옴 길)
④ 쓰는 곳 있으면 지움 막음(409) · 쓰는 곳 없으면 지움 · 없는 키 = 404.
"""
from __future__ import annotations
import pytest
from M01_MasterData import M01_MasterData_Store as m01
from M02_MasterTemplete import M02_Library_Uses as library_uses
from M02_MasterTemplete import M02_MasterTemplete_Store as store
from M02_MasterTemplete import M02_Material_Own as own
from resources.tester.test_m02_labor_ref import world # noqa: F401 — 같은 임시 층
NAME = "sub4임시자재"
def _at(folder, fn, *args):
with store.at(folder):
return fn(*args)
def _code(fn, *args) -> int:
with pytest.raises(store.StoreError) as e:
fn(*args)
return e.value.status
def _doc(key: str, code: str) -> dict:
"""줄 쌓기 재료 줄 하나(화면이 저장하는 꼴) — 단가 = 요소 이음(내 재료)."""
var = {"기호": "P", "아래": "재", "위": "", "이름": NAME, "단위": "",
"연결": {"갈래": "요소", "키": code, "단위": "kg"}} # fmt: skip
line = {"이름": NAME, "단위": "kg", "비목": "재료비", "수량": "2", "단가": "P_재"}
return {"꼴": "수식문서", "판": 1, "키": key, "이름": NAME, "결과단위": "원",
"변수": [var], "식": [], "금액": [line]} # fmt: skip
def test_m01_same_blocked(world):
me = world["personal"]
mt = next(r for r in m01.loaded()[1].index["MT"].values() if r.get("이름") and r.get("단위"))
same = {"이름": f" {mt['이름']} ", "규격": mt.get("규격") or "", "단위": mt["단위"], "값": 1}
assert _at(me, _code, own.add, me, same) == 409
assert _at(me, _code, own.add, me, {"이름": NAME, "단위": ""}) == 400
row = _at(me, own.add, me, {"이름": NAME, "규격": "x", "단위": "kg", "값": 1000})
assert own.is_own(row["키"]) and own.m01_same(row) is None
assert _at(me, _code, own.update, me, row["키"], same) == 409
assert _at(me, _code, own.update, me, "PM999999", {"이름": NAME, "단위": "kg"}) == 404
assert (
_at(me, _code, own.add, me, {"이름": NAME, "규격": "X", "단위": "㎏"}) == 409
) # 내 목록 같음
def test_sk_reads_and_follows(world):
from M02_MasterTemplete import M02_Doc_Sk_Path as path
from M02_MasterTemplete import M02_Labor_Ref as refs
me = world["personal"]
code = _at(me, own.add, me, {"이름": NAME, "규격": "y", "단위": "kg", "값": 1000})["키"]
sk = _at(me, lambda: refs.create("sangeun", {"이름": NAME, "단위": "식", "더한줄": []})["이름"])
doc = _doc(sk, code)
assert _at(me, path.preview, sk, {"문서": doc})["셈"]["계"] == 2000 # 저장 전 미리 셈
_at(me, path.save, sk, {"문서": doc, "판": _at(me, path.read, sk)["판"]})
assert _at(me, path.read, sk)["셈"]["계"] == 2000
_at(me, own.update, me, code, {"이름": NAME, "규격": "y", "단위": "kg", "값": 1500})
assert _at(me, path.read, sk)["셈"]["계"] == 3000 # 값 바꿈 → 따라옴
assert [u["키"] for u in library_uses.materials(me, [code])[code]] == [sk]
assert _at(me, _code, own.remove, me, code) == 409 # 쓰는 곳 있음
_at(me, store.delete, "sangeun", sk)
aside = me / "_합친것" / f"{sk}.json" # 파생 · 보관 폴더 = 쓰는 곳 아님
aside.parent.mkdir(parents=True, exist_ok=True)
aside.write_text(f'{{"이름": "x", "키": "{code}"}}', encoding="utf-8")
_at(me, own.remove, me, code)
assert all(r["키"] != code for r in own.rows(me))
assert _at(me, _code, own.remove, me, code) == 404