Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0148XFUpPfpiuTjxF1EK9c95
55 lines
2.1 KiB
Python
55 lines
2.1 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.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):
|
|
assert (
|
|
client.put("/api/m02/templates/table/a..b", json={"판": "", "문서": {}}).status_code == 200
|
|
)
|
|
assert (
|
|
client.put("/api/m02/templates/table/.숨김", json={"판": "", "문서": {}}).status_code == 422
|
|
)
|
|
assert client.put("/api/m02/templates/other/x", json={"판": "", "문서": {}}).status_code == 404
|