Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- 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>
This commit is contained in:
commit
0ed20bb838
90 changed files with 8545 additions and 0 deletions
125
tests/test_feed.py
Normal file
125
tests/test_feed.py
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
from datetime import datetime, timedelta, 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 _seed(db_session):
|
||||
channel_a = Channel(youtube_channel_id="chanA", title="Channel A", subscribed=True)
|
||||
channel_b = Channel(youtube_channel_id="chanB", title="Channel B", subscribed=True)
|
||||
db_session.add_all([channel_a, channel_b])
|
||||
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_a.id, category_id=category.id))
|
||||
db_session.commit()
|
||||
|
||||
base = datetime(2026, 9, 10, tzinfo=timezone.utc)
|
||||
videos = []
|
||||
for i in range(5):
|
||||
video = Video(
|
||||
youtube_video_id=f"vid{i}",
|
||||
channel_id=channel_a.id if i % 2 == 0 else channel_b.id,
|
||||
title=f"Video {i}",
|
||||
published_at=base + timedelta(hours=i),
|
||||
youtube_url=f"https://www.youtube.com/watch?v=vid{i}",
|
||||
)
|
||||
videos.append(video)
|
||||
db_session.add_all(videos)
|
||||
db_session.commit()
|
||||
|
||||
return channel_a, channel_b, category, videos
|
||||
|
||||
|
||||
def test_feed_orders_by_published_at_desc(client, db_session):
|
||||
_seed(db_session)
|
||||
|
||||
resp = client.get("/api/feed").json()
|
||||
|
||||
ids = [item["youtube_video_id"] for item in resp["items"]]
|
||||
assert ids == ["vid4", "vid3", "vid2", "vid1", "vid0"]
|
||||
assert resp["next_cursor"] is None
|
||||
|
||||
|
||||
def test_feed_pagination_cursor(client, db_session):
|
||||
_seed(db_session)
|
||||
|
||||
page1 = client.get("/api/feed?limit=2").json()
|
||||
assert [i["youtube_video_id"] for i in page1["items"]] == ["vid4", "vid3"]
|
||||
assert page1["next_cursor"] is not None
|
||||
|
||||
page2 = client.get(f"/api/feed?limit=2&cursor={page1['next_cursor']}").json()
|
||||
assert [i["youtube_video_id"] for i in page2["items"]] == ["vid2", "vid1"]
|
||||
assert page2["next_cursor"] is not None
|
||||
|
||||
page3 = client.get(f"/api/feed?limit=2&cursor={page2['next_cursor']}").json()
|
||||
assert [i["youtube_video_id"] for i in page3["items"]] == ["vid0"]
|
||||
assert page3["next_cursor"] is None
|
||||
|
||||
|
||||
def test_feed_filters_by_category(client, db_session):
|
||||
_, _, category, _ = _seed(db_session)
|
||||
|
||||
resp = client.get(f"/api/feed?category_id={category.id}").json()
|
||||
|
||||
ids = {i["youtube_video_id"] for i in resp["items"]}
|
||||
assert ids == {"vid0", "vid2", "vid4"}
|
||||
|
||||
|
||||
def test_feed_filters_by_channel(client, db_session):
|
||||
channel_a, channel_b, _, _ = _seed(db_session)
|
||||
|
||||
resp = client.get(f"/api/feed?channel_id={channel_b.id}").json()
|
||||
|
||||
ids = {i["youtube_video_id"] for i in resp["items"]}
|
||||
assert ids == {"vid1", "vid3"}
|
||||
|
||||
|
||||
def test_feed_filters_uncategorized(client, db_session):
|
||||
_seed(db_session)
|
||||
|
||||
resp = client.get("/api/feed?uncategorized=true").json()
|
||||
|
||||
ids = {i["youtube_video_id"] for i in resp["items"]}
|
||||
assert ids == {"vid1", "vid3"}
|
||||
|
||||
|
||||
def test_feed_item_shape(client, db_session):
|
||||
channel_a, _, category, _ = _seed(db_session)
|
||||
|
||||
resp = client.get("/api/feed?limit=1").json()
|
||||
item = resp["items"][0]
|
||||
|
||||
assert item["channel"]["id"] == item["channel"]["id"]
|
||||
assert set(item["channel"].keys()) == {"id", "youtube_channel_id", "title", "thumbnail_url"}
|
||||
assert item["local"] == {
|
||||
"available": False,
|
||||
"status": "not_downloaded",
|
||||
"progress_percent": None,
|
||||
"media_url": None,
|
||||
}
|
||||
assert isinstance(item["categories"], list)
|
||||
Loading…
Add table
Add a link
Reference in a new issue