douyinWEB/backend/tests/test_shorts_yt_quota.py
eric 1112a4d055 Handle YouTube Video Uploads daily quota (429) with project budget and pause-until-reset.
Add shorts_yt_quota module, Shorts UI quota banner, overview tweaks (hide upcoming opens, align events panel height), Electron desktop client scaffold, and deploy scripts; update README.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-11 02:04:44 -05:00

49 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import time
from app.shorts_upload import is_upload_quota_error
from app.shorts_yt_quota import (
YT_DAILY_UPLOAD_LIMIT_DEFAULT,
pause_uploads_until_reset,
reserve_yt_upload_slot,
yt_upload_budget,
)
from app.timeutil import pacific_day_from_ts
def test_is_upload_quota_error_matches_429():
err = 'Quota exceeded for quota metric "Video Uploads" and limit "Video Uploads per day"'
assert is_upload_quota_error(err)
def test_yt_upload_budget_and_reserve(temp_db):
cfg = temp_db.get_settings_map()
limit, used, remaining = yt_upload_budget(cfg)
assert limit == YT_DAILY_UPLOAD_LIMIT_DEFAULT
assert used >= 0
assert remaining == limit - used
assert reserve_yt_upload_slot(cfg) is True
_, used2, remaining2 = yt_upload_budget(temp_db.get_settings_map())
assert used2 == used + 1
assert remaining2 == remaining - 1
def test_pause_uploads_defers_jobs(temp_db):
ch = temp_db.create_shorts_channel(name="Y", enabled=True)
job = temp_db.create_shorts_job(session_id="", room_id="r1", channel_pk=ch["id"])
temp_db.update_shorts_job(job["id"], status="scheduled", clip_path="/tmp/x.mp4", upload_at=time.time())
until = pause_uploads_until_reset(temp_db.get_settings_map(), reason="test pause")
refreshed = temp_db.get_shorts_job(job["id"])
assert refreshed is not None
assert refreshed["status"] == "scheduled"
assert float(refreshed["upload_at"]) >= until
cfg = temp_db.get_settings_map()
assert float(cfg.get("shorts_yt_upload_blocked_until") or 0) >= until
def test_pacific_day_from_ts():
day = pacific_day_from_ts(time.time())
assert len(day) == 10 and day[4] == "-"