"""54-2 [?] 설명서 — 서버가 resources/help/<페이지>/*.md 를 부를 때마다 읽음(고치면 바로 바뀜).""" 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"]) def test_bad_page_refused(page): with pytest.raises(HTTPException): read_help(page) def test_root_is_repo_resources(): assert HELP_ROOT.parts[-2:] == ("resources", "help")