Files
gh-christianlouis-docuelevate/tests/test_views_help.py
copilot-swe-agent[bot] 46b2f17acc feat(docs): add built-in help section with How-To guides embedded in app
- Add MkDocs Material docs build stage to Dockerfile and Dockerfile.local
- Mount pre-built docs as static files at /help/ in FastAPI (app/main.py)
- Add app/views/help.py with /help → /help/ permanent redirect route
- Register help router in app/views/__init__.py
- Add Help nav link to base.html (public + app nav, desktop + mobile)
- Create how-to guides: HP printer, ScanSnap, watched folder, email ingestion, mobile scanning
- Update mkdocs.yml with How-To Guides section and Material theme palette
- Add optional docs service (squidfunk/mkdocs-material) to docker-compose.yaml with docs profile
- Add mkdocs-material to requirements-dev.txt
- Add /docs_build to .gitignore
- Add tests for help view (8 tests, 100% coverage on help.py)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-03-07 20:33:10 +00:00

93 lines
3.5 KiB
Python

"""Tests for app/views/help.py module."""
import pytest
@pytest.mark.integration
class TestHelpViews:
"""Tests for the help documentation view routes."""
def test_help_redirect(self, client):
"""GET /help should redirect permanently to /help/."""
response = client.get("/help", follow_redirects=False)
assert response.status_code == 301
assert response.headers["location"] in ("/help/", "http://testserver/help/")
def test_help_redirect_follows(self, client):
"""Following /help redirect leads to /help/ (docs served or 404 if not built)."""
# In test environments docs_build/ is not present, so /help/ may 404.
# We only verify the initial redirect works; the final landing page depends
# on whether the docs have been built (they are built only in Docker images).
response = client.get("/help", follow_redirects=False)
assert response.status_code == 301
# Redirect target must be /help/
location = response.headers.get("location", "")
assert location.endswith("/help/")
def test_help_route_is_registered(self, client):
"""Verify the /help route exists in the app router."""
# A GET to /help must not return 405 Method Not Allowed
response = client.get("/help", follow_redirects=False)
assert response.status_code != 405
@pytest.mark.unit
class TestHelpViewUnit:
"""Unit tests for the help view module."""
def test_help_redirect_returns_301(self):
"""Verify the redirect is HTTP 301 (permanent)."""
from fastapi import FastAPI
from fastapi.testclient import TestClient
from app.views.help import router
app = FastAPI()
app.include_router(router)
with TestClient(app) as tc:
resp = tc.get("/help", follow_redirects=False)
assert resp.status_code == 301
def test_help_redirect_target(self):
"""Verify the redirect points to /help/."""
from fastapi import FastAPI
from fastapi.testclient import TestClient
from app.views.help import router
app = FastAPI()
app.include_router(router)
with TestClient(app) as tc:
resp = tc.get("/help", follow_redirects=False)
assert resp.headers["location"].rstrip("/").endswith("help") or resp.headers["location"].endswith("/help/")
def test_docs_build_path_constant(self):
"""Verify _DOCS_BUILD_DIR is resolved relative to the app package."""
import pathlib
from app.views.help import _DOCS_BUILD_DIR
assert isinstance(_DOCS_BUILD_DIR, pathlib.Path)
# Should point to <repo_root>/docs_build
assert _DOCS_BUILD_DIR.name == "docs_build"
@pytest.mark.integration
class TestHelpNavigationLink:
"""Tests that the Help link appears in the navigation."""
def test_help_link_in_nav(self, client):
"""The Help navigation link should appear in the base template."""
response = client.get("/about")
assert response.status_code == 200
# The Help link should be present somewhere in the rendered page
assert b"/help/" in response.content
def test_help_link_has_accessible_text(self, client):
"""The Help link should have visible text for accessibility."""
response = client.get("/about")
assert response.status_code == 200
content = response.text
# Should include the word "Help" associated with /help/
assert "Help" in content