Files
siftlode/backend/tests/test_youtube_no_channel.py
peter 3ee00fb051 fix(logs): keep polling reads and a channel-less account out of the warnings
The reads the frontend polls (unread counts, /api/me, the download index,
sync status, subtitle progress) are logged at DEBUG: at INFO they were ~95%
of the stored log on prod. A scheduler job failure and a playlist sync
failure carry event codes, and a Google account without a YouTube channel
has an empty playlist list instead of a warning every six hours.
2026-09-19 04:51:31 +02:00

39 lines
1.6 KiB
Python

"""A Google account without a YouTube channel: its `mine` playlists read answers 404
`channelNotFound`. That is an empty list, not a failed sync — it came back as a warning every six
hours on prod for an account that will never have a channel."""
import logging
import httpx
import pytest
from app.youtube import client as yt
def _client(monkeypatch, status: int, reason: str) -> yt.YouTubeClient:
resp = httpx.Response(
status,
json={"error": {"code": status, "errors": [{"reason": reason, "message": "prose"}]}},
request=httpx.Request("GET", f"{yt.API_BASE}/playlists"),
)
c = yt.YouTubeClient.__new__(yt.YouTubeClient) # no HTTP client: `_send` is the stub
c.db = None
monkeypatch.setattr(yt.sysconfig, "get_str", lambda db, key: "")
monkeypatch.setattr(yt.quota, "record_usage", lambda cost: None)
monkeypatch.setattr(c, "_access_token", lambda: "t")
monkeypatch.setattr(c, "_send", lambda *a, **k: resp)
return c
def test_no_channel_is_an_empty_playlist_list_and_no_warning(monkeypatch, caplog):
caplog.set_level(logging.DEBUG, logger="siftlode")
assert list(_client(monkeypatch, 404, "channelNotFound").iter_my_playlists()) == []
assert not [r for r in caplog.records if r.levelno >= logging.WARNING]
def test_any_other_failure_still_raises_and_warns(monkeypatch, caplog):
caplog.set_level(logging.DEBUG, logger="siftlode")
with pytest.raises(yt.YouTubeError):
list(_client(monkeypatch, 403, "quotaExceeded").iter_my_playlists())
assert [r for r in caplog.records if r.levelno == logging.WARNING]