# -*- coding: utf-8 -*- from __future__ import annotations from app.youtube_live import _live_entry, _parse_batch_result def test_parse_batch_live(): row = { "ok": True, "is_live": True, "channel_id": "UCabc", "title": "Channel", "live": {"id": "vid123456789", "title": "Stream Title", "url": "https://www.youtube.com/watch?v=vid123456789"}, } entry = _parse_batch_result(row) assert entry["is_live"] is True assert entry["source"] == "youtubei" assert "watch?v=vid123456789" in entry["live_url"] assert entry["title"] == "Stream Title" def test_parse_batch_offline(): row = {"ok": True, "is_live": False, "channel_id": "UCabc"} entry = _parse_batch_result(row) assert entry["is_live"] is False assert "live_url" not in entry def test_parse_batch_error(): row = {"ok": False, "error": "timeout"} entry = _parse_batch_result(row) assert entry["is_live"] is False assert entry.get("error") def test_live_entry_minimal(): entry = _live_entry(is_live=True, source="oauth", live_url="https://youtube.com/watch?v=x", title="T") assert entry["is_live"] assert entry["source"] == "oauth" def test_parse_broadcast_shaped_as_search_not_required(): """Regression: offline oauth entry keeps channel_id.""" entry = _live_entry(is_live=False, source="oauth-broadcast", channel_id="UCabc") assert entry["is_live"] is False assert entry["channel_id"] == "UCabc" assert entry["source"] == "oauth-broadcast"