Files
ImpTune/tests/test_static.py
T
kawa 34c7cb30f1 feat(01-01): add test scaffold, health and static asset tests, fix deprecated APIs
- requirements-dev.txt with pytest and httpx
- tests/conftest.py: client and tmp_data_dir fixtures
- tests/test_health.py: GET /health returns 200 with {"status": "ok"}
- tests/test_static.py: no CDN URLs in templates, dashboard returns 200
- Fix imptune/api/pages.py: use request= kwarg in TemplateResponse (Starlette compat)
- Fix imptune/main.py: replace deprecated on_event with asynccontextmanager lifespan
2026-04-10 11:26:48 +02:00

38 lines
1.2 KiB
Python

import re
from pathlib import Path
CDN_PATTERNS = re.compile(
r"(cdn\.jsdelivr\.net|unpkg\.com|cdnjs\.com)",
re.IGNORECASE,
)
# Matches href="https://..." or src="https://..."
EXTERNAL_URL_PATTERN = re.compile(
r'(?:href|src)=["\']https?://',
re.IGNORECASE,
)
def test_no_cdn_urls_in_templates():
"""All .html templates use /static/ paths only — no CDN URLs in href/src attributes."""
templates_dir = Path(__file__).parent.parent / "imptune" / "templates"
html_files = list(templates_dir.glob("**/*.html"))
assert html_files, "No HTML templates found — check templates directory path"
violations = []
for html_file in html_files:
content = html_file.read_text(encoding="utf-8")
if CDN_PATTERNS.search(content):
violations.append(f"{html_file.name}: contains CDN domain reference")
if EXTERNAL_URL_PATTERN.search(content):
violations.append(f"{html_file.name}: contains external https:// in href/src")
assert not violations, "CDN/external URL violations found:\n" + "\n".join(violations)
def test_dashboard_returns_200(client):
"""GET / returns 200 (dashboard page)."""
response = client.get("/")
assert response.status_code == 200