- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck - Google OAuth (single allowed account), encrypted refresh token storage - Subscriptions sync with pagination, uploads playlist batch fetch - Categories CRUD, many-to-many channel assignment, category filtering - Video sync (playlistItems + videos.list batching), cached feed with cursor pagination, background scheduler (APScheduler) - Video detail page with YouTube embed player - SPA fallback routing, optimistic UI updates, client-side query caching 40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes, cursor pagination, and category filtering. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.db import get_db
|
|
from app.main import app
|
|
|
|
|
|
def _fake_db():
|
|
session = MagicMock()
|
|
session.execute.return_value = None
|
|
yield session
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def override_get_db():
|
|
app.dependency_overrides[get_db] = _fake_db
|
|
yield
|
|
del app.dependency_overrides[get_db]
|
|
|
|
|
|
def test_health_ok():
|
|
with patch("app.api.health.httpx.get") as mock_get:
|
|
mock_get.return_value = MagicMock(status_code=200)
|
|
client = TestClient(app)
|
|
response = client.get("/api/health")
|
|
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["status"] == "ok"
|
|
assert body["database"] == "ok"
|
|
assert body["metube"] == "ok"
|
|
|
|
|
|
def test_health_metube_unreachable():
|
|
with patch("app.api.health.httpx.get", side_effect=ConnectionError):
|
|
client = TestClient(app)
|
|
response = client.get("/api/health")
|
|
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["metube"] == "error"
|