homelab_automation/tests/test_help_downloads.py

50 lines
1.4 KiB
Python

"""Tests for help documentation download endpoints helpers.
We keep this lightweight by validating that the help endpoints are registered
and that the PDF generator returns a non-empty PDF payload.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
import pytest
# Ensure project root on path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
@pytest.mark.asyncio
async def test_help_markdown_builder_exists_and_non_empty():
from app import app_optimized # type: ignore
assert hasattr(app_optimized, "_build_help_markdown")
md = app_optimized._build_help_markdown()
assert isinstance(md, str)
assert len(md) > 100
assert "Guide d'Utilisation" in md or "Démarrage Rapide" in md
@pytest.mark.asyncio
async def test_help_pdf_generator_returns_pdf_bytes():
pytest.importorskip("reportlab")
pytest.importorskip("PIL")
from app import app_optimized # type: ignore
md = app_optimized._build_help_markdown()
pdf_bytes = app_optimized._markdown_to_pdf_bytes(md)
assert isinstance(pdf_bytes, (bytes, bytearray))
assert len(pdf_bytes) > 1000
assert bytes(pdf_bytes[:4]) == b"%PDF"
def test_help_routes_registered():
from app.app_optimized import app # type: ignore
paths = {r.path for r in app.routes}
assert "/api/help/documentation.md" in paths
assert "/api/help/documentation.pdf" in paths