Some checks failed
CICD Start / Sanity and Base Decision (push) Failing after 13m23s
## Summary This PR upgrades backend typing tooling and finalizes quality cleanup for the SQLAlchemy async engine/session work on `PP-11_Add_SQLAlchemy_async_engine_session`. ## What Changed - Upgraded pinned `pyright` version from `1.1.406` to `1.1.410`. - Regenerated backend lock state to align with the new pyright pin. - Removed deprecated `pythonPath` from pyright config to eliminate the config notice. - Refined backend DB runtime state handling and cleanup paths. - Updated database tests to avoid brittle singleton assumptions and keep typeguard-compatible async engine test doubles. ## Why - Remove tooling noise and keep checks deterministic. - Keep backend static/type/doc/test quality gates warning-free. - Improve reliability and clarity of DB engine/session lifecycle tests. ## Validation - `uv run ruff format --check .` - `uv run ruff check .` - `uv run pyright .` - `uv run pydoclint --config=pyproject.toml src/` - `uv run xdoctest --module backend` - `uv run pytest` Results: - Pyright: `0 errors, 0 warnings` - Pytest: `21 passed` ## Impact - No API contract changes intended. - No frontend changes. - Backend behavior remains the same; this is tooling/test/runtime-state cleanup. ## Risk - Low risk. - Main touched areas are backend tooling config, lockfile, DB runtime state internals, and tests. ## Checklist - [x] Backend lint clean - [x] Backend type checks clean - [x] Backend doc checks clean - [x] Backend tests passing - [x] Branch pushed and ready for review Co-authored-by: copilotcoder <copilotcoder@darkhelm.org> Reviewed-on: #67
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
"""Basic tests for the backend application."""
|
|
|
|
from typing import cast
|
|
from unittest.mock import AsyncMock
|
|
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from backend.main import app, get_api_session, read_root
|
|
|
|
|
|
def test_app_creation():
|
|
"""Test that the FastAPI app is created properly."""
|
|
assert app is not None
|
|
assert app.title == "Plex Playlist Backend"
|
|
assert app.version == "0.1.0"
|
|
|
|
|
|
def test_read_root():
|
|
"""Test the root endpoint function."""
|
|
result = read_root()
|
|
assert result == {"message": "Plex Playlist Backend API"}
|
|
|
|
|
|
def test_health_check():
|
|
"""Test the health check endpoint function."""
|
|
|
|
healthy_session = cast("AsyncSession", AsyncMock(spec=AsyncSession))
|
|
healthy_session.execute = AsyncMock(return_value=1)
|
|
|
|
async def override_get_session():
|
|
"""Provide a healthy session dependency override for tests."""
|
|
yield healthy_session
|
|
|
|
app.dependency_overrides[get_api_session] = override_get_session
|
|
try:
|
|
with TestClient(app) as client:
|
|
response = client.get("/health")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json() == {"status": "healthy", "database": "connected"}
|
|
finally:
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
def test_typeguard_validation():
|
|
"""Test that typeguard is working for type validation."""
|
|
|
|
# Test a function with type hints to ensure typeguard is active
|
|
def typed_function(x: int, y: str) -> str:
|
|
return f"{x}: {y}"
|
|
|
|
# This should work fine
|
|
result = typed_function(42, "test")
|
|
assert result == "42: test"
|
|
|
|
# This would fail with typeguard active, but we'll just test the happy path
|
|
# to ensure coverage of our code without breaking the test
|