- 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>
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from datetime import datetime, timezone
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.core.auth_dependency import require_session
|
|
from app.db import get_db
|
|
from app.main import app
|
|
from app.models.category import Category
|
|
from app.models.channel import Channel
|
|
from app.models.channel_category import channel_categories
|
|
from app.models.video import Video
|
|
|
|
|
|
@pytest.fixture
|
|
def client(db_session):
|
|
def _get_db_override():
|
|
yield db_session
|
|
|
|
app.dependency_overrides[get_db] = _get_db_override
|
|
app.dependency_overrides[require_session] = lambda: None
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
del app.dependency_overrides[get_db]
|
|
del app.dependency_overrides[require_session]
|
|
|
|
|
|
def test_get_video_by_youtube_id(client, db_session):
|
|
channel = Channel(youtube_channel_id="chanA", title="Channel A", subscribed=True)
|
|
db_session.add(channel)
|
|
db_session.commit()
|
|
|
|
category = Category(name="Linux", slug="linux", sort_order=0)
|
|
db_session.add(category)
|
|
db_session.commit()
|
|
db_session.execute(channel_categories.insert().values(channel_id=channel.id, category_id=category.id))
|
|
db_session.commit()
|
|
|
|
video = Video(
|
|
youtube_video_id="vid1",
|
|
channel_id=channel.id,
|
|
title="Video One",
|
|
description="desc",
|
|
published_at=datetime(2026, 9, 10, tzinfo=timezone.utc),
|
|
duration_seconds=125,
|
|
youtube_url="https://www.youtube.com/watch?v=vid1",
|
|
)
|
|
db_session.add(video)
|
|
db_session.commit()
|
|
|
|
resp = client.get("/api/videos/vid1")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body["youtube_video_id"] == "vid1"
|
|
assert body["channel"]["id"] == channel.id
|
|
assert body["categories"] == [{"id": category.id, "name": "Linux"}]
|
|
assert body["local"]["available"] is False
|
|
|
|
|
|
def test_get_video_not_found(client):
|
|
resp = client.get("/api/videos/missing")
|
|
assert resp.status_code == 404
|