43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Unit: complete_active_live_broadcast filters lifeCycleStatus."""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from typing import Any
|
|
|
|
from app import youtube_manage
|
|
|
|
|
|
def test_complete_active_live_broadcast_completes_live(monkeypatch):
|
|
async def fake_access(pk: str):
|
|
return "tok", {"id": pk}
|
|
|
|
calls: list[dict[str, Any]] = []
|
|
|
|
async def fake_get(path: str, *, token: str, params: dict[str, Any]):
|
|
assert path == "liveBroadcasts"
|
|
return {
|
|
"items": [
|
|
{"id": "vid_live", "status": {"lifeCycleStatus": "live"}},
|
|
{"id": "vid_complete", "status": {"lifeCycleStatus": "complete"}},
|
|
{"id": "vid_ready", "status": {"lifeCycleStatus": "ready"}},
|
|
]
|
|
}
|
|
|
|
async def fake_post(path: str, *, token: str, params: dict[str, Any], json_body: dict[str, Any]):
|
|
calls.append({"path": path, "params": params})
|
|
return {"id": params.get("id"), "status": {"lifeCycleStatus": "complete"}}
|
|
|
|
monkeypatch.setattr(youtube_manage, "_access_for_channel", fake_access)
|
|
monkeypatch.setattr(youtube_manage, "_get", fake_get)
|
|
monkeypatch.setattr(youtube_manage, "_post", fake_post)
|
|
|
|
out = asyncio.run(youtube_manage.complete_active_live_broadcast("ch1"))
|
|
assert out["completed"] == ["vid_live"]
|
|
assert calls and calls[0]["params"]["broadcastStatus"] == "complete"
|
|
|
|
|
|
def test_complete_empty_pk():
|
|
out = asyncio.run(youtube_manage.complete_active_live_broadcast(""))
|
|
assert out["ok"] is False
|