douyinWEB/backend/tests/test_tiktok_assign.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

56 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
import time
from app import tiktok_db
from app import tiktok_session
def test_pick_soft_assign_when_quota_full(temp_db, tmp_path, monkeypatch):
monkeypatch.setattr(tiktok_session, "cookies_dir", lambda: tmp_path)
ch = tiktok_db.create_tiktok_channel(name="tt-quota")
tiktok_session.save_session_from_values(ch["id"], sessionid="sid", dc_id="useast5a")
day = "2099-01-01"
for i in range(9):
job = tiktok_db.create_tiktok_job(
session_id="",
room_id=f"r{i}",
channel_pk=ch["id"],
push_date=day,
)
assert job
tiktok_db.update_tiktok_job(job["id"], status="scheduled")
assert tiktok_db.tiktok_channel_upload_count(ch["id"], day) == 9
assert tiktok_db.pick_tiktok_channel(day, require_quota=True) is None
soft = tiktok_db.pick_tiktok_channel(day, require_quota=False)
assert soft is not None
assert soft["id"] == ch["id"]
def test_pending_jobs_do_not_consume_upload_quota(temp_db, tmp_path, monkeypatch):
monkeypatch.setattr(tiktok_session, "cookies_dir", lambda: tmp_path)
ch = tiktok_db.create_tiktok_channel(name="tt-pending")
tiktok_session.save_session_from_values(ch["id"], sessionid="sid", dc_id="useast5a")
day = "2099-01-02"
for i in range(12):
tiktok_db.create_tiktok_job(
session_id="",
room_id=f"p{i}",
channel_pk=ch["id"],
push_date=day,
)
assert tiktok_db.tiktok_channel_upload_count(ch["id"], day) == 0
assert tiktok_db.pick_tiktok_channel(day, require_quota=True) is not None
def test_ensure_assigns_missing_channel(temp_db, tmp_path, monkeypatch):
monkeypatch.setattr(tiktok_session, "cookies_dir", lambda: tmp_path)
ch = tiktok_db.create_tiktok_channel(name="tt-ens")
tiktok_session.save_session_from_values(ch["id"], sessionid="sid", dc_id="useast5a")
job = tiktok_db.create_tiktok_job(session_id="", room_id="orphan1", channel_pk="", push_date="2099-01-03")
assert job
assert not job.get("channel_pk")
assigned = tiktok_db.ensure_tiktok_job_channel(job, require_quota=False)
assert assigned and assigned["id"] == ch["id"]
fresh = tiktok_db.get_tiktok_job(job["id"])
assert fresh["channel_pk"] == ch["id"]