# retoor import re from molodetz.docs_prose import DOCS_PAGES, PROSE_DIR, SECTIONS BANNED_SECTION = "Contributing and internals" BANNED_TITLES = { "Architecture", "Frontend and components", "dp-avatar", "dp-code", "dp-content", "dp-title", "dp-toast", "dp-dialog", "dp-context-menu", "dp-upload", "dp-lightbox", "dp-chat", } BANNED_SLUGS = { "architecture", "frontend", "component-avatar", "component-code", "component-content", "component-title", "component-toast", "component-dialog", "component-context-menu", "component-upload", "component-lightbox", "component-chat", } BANNED_FILES = { "architecture.md", "frontend.md", *[ f"component-{name}.md" for name in ( "avatar", "code", "content", "title", "toast", "dialog", "context-menu", "upload", "lightbox", "chat", ) ], } def _docs_surfaces(html): sidebar = re.search(r'', html, re.S) content = re.search(r'
(.*?)
', html, re.S) return (sidebar.group(1) if sidebar else ""), (content.group(1) if content else "") def test_docs_registry_excludes_removed_internals(): assert BANNED_SECTION not in SECTIONS titles = {page["title"] for page in DOCS_PAGES} slugs = {page["slug"] for page in DOCS_PAGES} sections = {page["section"] for page in DOCS_PAGES} assert not titles & BANNED_TITLES assert not slugs & BANNED_SLUGS assert BANNED_SECTION not in sections for name in BANNED_FILES: assert not (PROSE_DIR / name).exists(), name def test_served_docs_hide_removed_internals(anon, admin): banned_hrefs = {f"/docs/{slug}" for slug in BANNED_SLUGS} for client in (anon, admin): for path in ("/docs", "/docs/welcome", "/docs/api"): html = client.get(path).text sidebar, content = _docs_surfaces(html) surface = f"{sidebar}\n{content}" assert BANNED_SECTION not in surface, path for title in BANNED_TITLES: assert title not in surface, (path, title) for href in banned_hrefs: assert href not in surface, (path, href) for slug in sorted(BANNED_SLUGS): assert anon.get(f"/docs/{slug}").status_code == 404, slug