Shared endpoint enricher builds curl, request, and response samples for every registry endpoint so download.md/html stay complete without a hand-maintained duplicate. Group pages reuse the same curl builder.
87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
import json
|
|
|
|
from molodetz.docs_api import ordered_groups
|
|
from molodetz.docs_export import enrich_endpoint, export_markdown
|
|
|
|
|
|
def test_download_md_lists_each_api_group_and_known_samples(anon):
|
|
body = anon.get("/docs/download.md").text
|
|
assert body.startswith("# Molodetz documentation")
|
|
for title in ("Content", "Join", "Account"):
|
|
assert f"## API: {title}" in body
|
|
assert "## API: Admin" not in body
|
|
assert '"status": "ok"' in body
|
|
assert "probe@example.com" in body
|
|
assert "#### Request sample" in body
|
|
assert "#### Response sample" in body
|
|
assert "curl -X GET" in body
|
|
|
|
|
|
def test_download_html_lists_each_api_group_and_known_samples(anon):
|
|
body = anon.get("/docs/download.html").text
|
|
assert "Molodetz documentation" in body
|
|
for title in ("Content", "Join", "Account"):
|
|
assert f"API: {title}" in body
|
|
assert "API: Admin" not in body
|
|
assert "status" in body and "ok" in body
|
|
assert ""status": "ok"" in body
|
|
assert "probe@example.com" in body
|
|
|
|
|
|
def test_download_includes_every_registry_endpoint_and_sample(anon):
|
|
body = anon.get("/docs/download.md").text
|
|
for group in ordered_groups():
|
|
if group["slug"] == "admin":
|
|
continue
|
|
assert f"## API: {group['title']}" in body
|
|
assert group["description"] in body
|
|
for item in group["endpoints"]:
|
|
assert f"{item['method']} {item['path']}" in body, item["path"]
|
|
assert f"**Auth:** {item['auth']}" in body
|
|
enriched = enrich_endpoint(item)
|
|
assert enriched["curl"] in body
|
|
if enriched["response_sample"] is not None:
|
|
blob = json.dumps(enriched["response_sample"], indent=2, ensure_ascii=False, sort_keys=True)
|
|
assert blob in body, item["path"]
|
|
if enriched["request_sample"] is not None:
|
|
blob = json.dumps(enriched["request_sample"], indent=2, ensure_ascii=False, sort_keys=True)
|
|
assert blob in body, item["path"]
|
|
|
|
|
|
def test_download_auto_includes_new_registry_sample(monkeypatch):
|
|
from molodetz.docs_api import content
|
|
|
|
original = list(content.GROUP["endpoints"])
|
|
marker = {"auto_include_probe": "download-must-show-this-token-9f3a"}
|
|
try:
|
|
content.GROUP["endpoints"] = original + [
|
|
{
|
|
"method": "GET",
|
|
"path": "/__docs_auto_include_probe",
|
|
"title": "Auto include probe",
|
|
"description": "Temporary registry probe for download coverage.",
|
|
"auth": "public",
|
|
"min_role": "guest",
|
|
"fields": [],
|
|
"sample": marker,
|
|
"negotiation": "json",
|
|
"destructive": False,
|
|
"interactive": False,
|
|
"probe_path": "/__docs_auto_include_probe",
|
|
"probe_body": None,
|
|
}
|
|
]
|
|
body = export_markdown(False)
|
|
assert "GET /__docs_auto_include_probe" in body
|
|
assert "download-must-show-this-token-9f3a" in body
|
|
assert "Auto include probe" in body
|
|
finally:
|
|
content.GROUP["endpoints"] = original
|
|
|
|
|
|
def test_admin_download_includes_admin_group(admin):
|
|
body = admin.get("/docs/download.md").text
|
|
assert "## API: Admin" in body
|
|
assert "GET /admin" in body
|