- 서버 목록이 쓰는 양식(구조물집계표 · B07 도각 · 방위표 · 표지)에 `쓰는곳` 을 실음 — IN_USE 한 벌
- 좌측 [지우기] 가 `쓰는곳` 이 있으면 확인 창 없이 「쓰는 양식이라 못 지움 「이름」 — 쓰는 곳」 알림
- 서버 409 막기(6606ef16)는 그대로 두 겹 · M01 화면은 안 건드림
- 시험: 목록의 `쓰는곳` 대조 · ORCA 5180 에서 방위표 · 구조물집계표는 확인 창 없이 알림, 임시 양식은 확인 창 뒤 지워짐(만든 것 되돌림)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013zGnt85s95baQ72rhKBCJ4
121 lines
5.8 KiB
Python
121 lines
5.8 KiB
Python
"""M02 시스템 층 저장소·길 — 새로·저장·다시 열기·지우기·409 (사본 폴더로)."""
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
|
from M02_MasterTemplete import M02_Template_Layers as layers
|
|
from M02_MasterTemplete.M02_MasterTemplete_Router import router
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(tmp_path, monkeypatch):
|
|
for kind in store.KINDS:
|
|
(tmp_path / kind).mkdir()
|
|
monkeypatch.setattr(store, "FOLDER", tmp_path)
|
|
app = FastAPI()
|
|
app.include_router(router)
|
|
return TestClient(app)
|
|
|
|
|
|
def test_new_save_reopen_delete_and_stale(client):
|
|
assert client.get("/api/m02/templates").json() == []
|
|
|
|
made = client.put("/api/m02/templates/table/집계표", json={"판": "", "문서": {"열": [1]}})
|
|
assert made.status_code == 200
|
|
v1 = made.json()["판"]
|
|
assert (
|
|
client.put(
|
|
"/api/m02/templates/table/집계표", json={"판": "", "문서": {"열": []}}
|
|
).status_code
|
|
== 409
|
|
)
|
|
|
|
got = client.get("/api/m02/templates/table/집계표").json()
|
|
assert got["판"] == v1 and got["문서"] == {"열": [1]}
|
|
|
|
saved = client.put("/api/m02/templates/table/집계표", json={"판": v1, "문서": {"열": [1, 2]}})
|
|
assert saved.status_code == 200 and saved.json()["판"] != v1
|
|
stale = client.put("/api/m02/templates/table/집계표", json={"판": v1, "문서": {"열": []}})
|
|
assert stale.status_code == 409 and stale.json()["detail"]["stale"] == ["집계표"]
|
|
|
|
rows = client.get("/api/m02/templates").json()
|
|
assert [(r["종류"], r["이름"]) for r in rows] == [("table", "집계표")]
|
|
|
|
assert client.delete("/api/m02/templates/table/집계표").status_code == 200
|
|
assert client.get("/api/m02/templates/table/집계표").status_code == 404
|
|
|
|
|
|
def test_bad_names_and_kinds(client):
|
|
for bad in ("a..b", ".숨김", "a%5Cb", "a%3Ab", "_밑줄", "가" * 81):
|
|
got = client.put(f"/api/m02/templates/table/{bad}", json={"판": "", "문서": {"열": []}})
|
|
assert got.status_code == 400 and "쓸 수 없는" in got.json()["detail"]
|
|
assert client.put("/api/m02/templates/other/x", json={"판": "", "문서": {}}).status_code == 404
|
|
edge = "가" * 80 # 80자는 됨
|
|
assert (
|
|
client.put(
|
|
f"/api/m02/templates/table/{edge}", json={"판": "", "문서": {"열": []}}
|
|
).status_code
|
|
== 200
|
|
)
|
|
|
|
|
|
def test_copy_is_independent_and_seeds_new_project(client, tmp_path, monkeypatch):
|
|
"""본떠 만들기 = 읽어 새 이름으로 새로 저장 — 원본은 안 바뀜 · 새 프로젝트 복사에 실림."""
|
|
doc = {"format": 6, "entities": [{"type": "line"}], "drawing_area": [1, 2, 3, 4]}
|
|
client.put("/api/m02/templates/drawing/원본", json={"판": "", "문서": doc})
|
|
got = client.get("/api/m02/templates/drawing/원본").json()
|
|
made = client.put("/api/m02/templates/drawing/복사", json={"판": "", "문서": got["문서"]})
|
|
assert made.status_code == 200
|
|
assert (
|
|
client.put("/api/m02/templates/drawing/복사", json={"판": "", "문서": doc}).status_code
|
|
== 409
|
|
)
|
|
copy = client.get("/api/m02/templates/drawing/복사").json()
|
|
assert copy["문서"] == doc and copy["판"] == got["판"] # 내용 같음
|
|
client.put(
|
|
"/api/m02/templates/drawing/복사",
|
|
json={"판": copy["판"], "문서": {**doc, "entities": [{"type": "line"}, {"type": "arc"}]}},
|
|
)
|
|
assert client.get("/api/m02/templates/drawing/원본").json()["문서"] == doc # 원본 그대로
|
|
monkeypatch.setattr(layers, "SYSTEM_ROOT", tmp_path)
|
|
copied = layers.seed_project(tmp_path / "seed")
|
|
assert {"drawing/원본", "drawing/복사"} <= set(copied["작업본"])
|
|
client.delete("/api/m02/templates/drawing/복사")
|
|
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
|
|
# 목록이 쓰는 곳을 실어 화면이 확인 창 전에 막음 · 안 쓰는 양식엔 없음
|
|
client.put("/api/m02/templates/drawing/아무도", json={"판": "", "문서": doc})
|
|
rows = {(r["종류"], r["이름"]): r for r in client.get("/api/m02/templates").json()}
|
|
for key, use in store.IN_USE.items():
|
|
assert rows[key]["쓰는곳"] == use
|
|
assert "쓰는곳" not in rows[("drawing", "아무도")]
|
|
|
|
|
|
def test_empty_doc_rejected_and_file_untouched(client):
|
|
good = {"format": 6, "entities": [{"type": "line"}]}
|
|
made = client.put("/api/m02/templates/drawing/도", json={"판": "", "문서": good})
|
|
v = made.json()["판"]
|
|
for bad in ({}, {"format": 6}, {"entities": "x"}, []):
|
|
r = client.put("/api/m02/templates/drawing/도", json={"판": v, "문서": bad})
|
|
assert r.status_code == 400
|
|
assert client.put("/api/m02/templates/table/표", json={"판": "", "문서": {}}).status_code == 400
|
|
assert client.get("/api/m02/templates/drawing/도").json()["문서"] == good
|
|
assert client.get("/api/m02/templates/table/표").status_code == 404
|