diff --git a/M02_MasterTemplete/M02_MasterTemplete_Store.py b/M02_MasterTemplete/M02_MasterTemplete_Store.py index c846c529..30ded48a 100644 --- a/M02_MasterTemplete/M02_MasterTemplete_Store.py +++ b/M02_MasterTemplete/M02_MasterTemplete_Store.py @@ -27,6 +27,13 @@ KINDS = layers.KINDS # 시험은 FOLDER 를 사본으로 바꿈 # (제목행 = 열 `머리` 네 층 · 없는 층 00) — 한 열의 세 번호는 같은 8자리 · # 한 번 준 번호는 파일에 남아 안 바뀜(PLAN 13장) STRUCTURE_TABLE = "구조물집계표" +# 프로그램이 이름으로 부르는 양식 — 지우면 그 기능이 죽음(B07 이름은 `B07_DesignDetail_Engine_*`) +IN_USE = { + ("table", STRUCTURE_TABLE): "구조물 도면 · 면적산출 · 재료산출 · 조합 장부가 씀", + ("drawing", "00_template_A1"): "B07 도면 도각", + ("drawing", "00_template_compass"): "B07 방위표", + ("drawing", "00_template_cover"): "B07 표지", +} # (종류, 문서 번호 칸, 머리 글자, 시트 이름) — 시트 이름이 None 이면 구조물 도면 PARTS = ( ("structure", "도번", "SD", None), @@ -138,6 +145,8 @@ def write(kind: str, name: str, version: str, doc: Any) -> dict[str, Any]: def delete(kind: str, name: str, version: str | None = None) -> None: path = _path(kind, name) + if (kind, name) in IN_USE: + raise StoreError(409, f"쓰는 양식이라 못 지움 「{name}」 — {IN_USE[(kind, name)]}") with _LOCK: if not path.is_file(): raise StoreError(404, f"없는 양식 「{name}」") diff --git a/resources/tester/test_m02_store.py b/resources/tester/test_m02_store.py index 33fa89a0..b4fb860a 100644 --- a/resources/tester/test_m02_store.py +++ b/resources/tester/test_m02_store.py @@ -86,6 +86,22 @@ def test_copy_is_independent_and_seeds_new_project(client, tmp_path, monkeypatch assert [r["이름"] for r in client.get("/api/m02/templates").json()] == ["원본"] +def test_in_use_templates_not_deleted(client): + """프로그램이 이름으로 부르는 양식은 못 지움 — 이름은 B07 엔진 상수와 같음.""" + from B07_DesignDetail import B07_DesignDetail_Engine_Cad_Cover as cover + from B07_DesignDetail import B07_DesignDetail_Engine_Template as tpl + + names = {tpl.A1_TEMPLATE, tpl.COMPASS_TEMPLATE, cover.COVER_TEMPLATE} + assert {n for k, n in store.IN_USE if k == "drawing"} == names + doc = {"format": 6, "entities": [{"type": "line"}]} + for kind, name in store.IN_USE: + body = doc if kind == "drawing" else {"열": []} + client.put(f"/api/m02/templates/{kind}/{name}", json={"판": "", "문서": body}) + got = client.delete(f"/api/m02/templates/{kind}/{name}") + assert got.status_code == 409 and "쓰는 양식" in got.json()["detail"] + assert client.get(f"/api/m02/templates/{kind}/{name}").status_code == 200 + + def test_empty_doc_rejected_and_file_untouched(client): good = {"format": 6, "entities": [{"type": "line"}]} made = client.put("/api/m02/templates/drawing/도", json={"판": "", "문서": good})