59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
"""54-2 [?] 설명서 — 서버가 resources/help/<페이지>/*.md 를 부를 때마다 읽음(고치면 바로 바뀜)."""
|
|
|
|
import re
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
from common_util.common_util_help_router import HELP_ROOT, read_help
|
|
|
|
|
|
def test_every_page_has_manual_first():
|
|
for n in range(2, 10):
|
|
items = read_help(f"B0{n}")
|
|
assert items and items[0]["key"] == "00_설명서"
|
|
|
|
|
|
def test_title_order_and_live_edit():
|
|
tmp_path = Path(tempfile.mkdtemp())
|
|
page = tmp_path / "B05"
|
|
page.mkdir()
|
|
(page / "10_배관.md").write_text("# 배관\n\n본문", encoding="utf-8")
|
|
(page / "00_설명서.md").write_text("제목 없음", encoding="utf-8")
|
|
items = read_help("B05", tmp_path)
|
|
assert [i["key"] for i in items] == ["00_설명서", "10_배관"]
|
|
assert [i["title"] for i in items] == ["00_설명서", "배관"]
|
|
(page / "10_배관.md").write_text("# 배관\n\n고친 글", encoding="utf-8")
|
|
assert "고친 글" in read_help("B05", tmp_path)[1]["text"]
|
|
|
|
|
|
@pytest.mark.parametrize("page", ["B01", "B10", "../B05", "b05", "D05", "E08", "C01"])
|
|
def test_bad_page_refused(page):
|
|
with pytest.raises(HTTPException):
|
|
read_help(page)
|
|
|
|
|
|
def test_529_1_D_E_pages_open_empty(tmp_path):
|
|
assert read_help("D02", tmp_path) == [] and read_help("E07", tmp_path) == []
|
|
|
|
|
|
def test_root_is_repo_resources():
|
|
assert HELP_ROOT.parts[-2:] == ("resources", "help")
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"page", ["D01", "D02", "D03", "D04", "E01", "E02", "E03", "E04", "E05", "E06", "E07"]
|
|
)
|
|
def test_d_e_pages_have_manual(page):
|
|
items = read_help(page)
|
|
assert items and items[0]["key"] == "00_설명서"
|
|
assert len(items[0]["text"]) > 400
|
|
for item in items: # 명사형 종결 — 합쇼체 · 해요체 · 한다체 금지
|
|
for line in item["text"].splitlines():
|
|
assert not re.search(r"(합니다|습니다|해요|세요|한다|된다|있다|없다)[.!]?\s*$", line), (
|
|
page,
|
|
line,
|
|
)
|