Some checks failed
Lint & Test / test (push) Failing after 48s
Security: tighten CORS defaults, add webhook rate limiting, fix XSS in automations, guard WebSocket JSON.parse, validate ADB address input, seal debug exception leak, URL-encode WS tokens, CSS.escape in selectors. Code quality: add Pydantic models for brightness/power endpoints, fix thread safety and name uniqueness in DeviceStore, immutable update pattern, split 6 oversized files into 16 focused modules, enable TypeScript strictNullChecks (741→102 errors), type state variables, add dom-utils helper, migrate 3 modules from inline onclick to event delegation, ProcessorDependencies dataclass. Performance: async store saves, health endpoint log level, command palette debounce, optimized entity-events comparison, fix service worker precache list. Testing: expand from 45 to 293 passing tests — add store tests (141), route tests (25), core logic tests (42), E2E flow tests (33), organize into tests/api/, tests/storage/, tests/core/, tests/e2e/. DevOps: CI test pipeline, pre-commit config, Dockerfile multi-stage build with non-root user and health check, docker-compose improvements, version bump to 0.2.0. Docs: rewrite CLAUDE.md (202→56 lines), server/CLAUDE.md (212→76), create contexts/server-operations.md, fix .js→.ts references, fix env var prefix in README, rewrite INSTALLATION.md, add CONTRIBUTING.md and .env.example.
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""Tests for API endpoints (public + authenticated)."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from wled_controller.main import app
|
|
from wled_controller import __version__
|
|
from wled_controller.config import get_config
|
|
|
|
client = TestClient(app)
|
|
|
|
# Build auth header from the first configured API key
|
|
_config = get_config()
|
|
_api_key = next(iter(_config.auth.api_keys.values()), "")
|
|
AUTH_HEADERS = {"Authorization": f"Bearer {_api_key}"} if _api_key else {}
|
|
|
|
|
|
def test_root_endpoint():
|
|
"""Test root endpoint returns the HTML dashboard."""
|
|
response = client.get("/")
|
|
assert response.status_code == 200
|
|
assert "text/html" in response.headers["content-type"]
|
|
|
|
|
|
def test_health_check():
|
|
"""Test health check endpoint."""
|
|
response = client.get("/health")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "healthy"
|
|
assert data["version"] == __version__
|
|
assert "timestamp" in data
|
|
|
|
|
|
def test_version_endpoint():
|
|
"""Test version endpoint."""
|
|
response = client.get("/api/v1/version")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["version"] == __version__
|
|
assert "python_version" in data
|
|
assert data["api_version"] == "v1"
|
|
|
|
|
|
def test_get_displays():
|
|
"""Test get displays endpoint (requires auth)."""
|
|
response = client.get("/api/v1/config/displays", headers=AUTH_HEADERS)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "displays" in data
|
|
assert "count" in data
|
|
assert isinstance(data["displays"], list)
|
|
assert data["count"] >= 0
|
|
|
|
# If displays are found, validate structure
|
|
if data["count"] > 0:
|
|
display = data["displays"][0]
|
|
assert "index" in display
|
|
assert "name" in display
|
|
assert "width" in display
|
|
assert "height" in display
|
|
assert "is_primary" in display
|
|
|
|
|
|
def test_openapi_docs():
|
|
"""Test OpenAPI documentation is available."""
|
|
response = client.get("/openapi.json")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["info"]["version"] == __version__
|
|
|
|
|
|
def test_swagger_ui():
|
|
"""Test Swagger UI is available."""
|
|
response = client.get("/docs")
|
|
assert response.status_code == 200
|
|
assert "text/html" in response.headers["content-type"]
|