feat: 오늘 화면 히어로 아래 날씨각 유튜브 쇼츠 줄 — 첫 카드 소리 없이 자동재생, 누르면 전체 화면에서 위아래로 넘겨 보기. 목록은 /v1/shorts(API 키 있으면 채널 쇼츠, 없으면 설정한 영상 ID), 1시간 캐시
This commit is contained in:
1 parent
f9988855d3
commit
b718955927
15 files changed
+875
-6
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import json
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from services.external.youtube import channel_shorts, seconds, video_title
|
||||
|
||||
|
||||
def test_seconds_parses_iso_duration():
|
||||
assert seconds("PT45S") == 45
|
||||
assert seconds("PT1M5S") == 65
|
||||
assert seconds("PT1H") == 3600
|
||||
assert seconds("P1D") is None
|
||||
|
||||
|
||||
def _api(videos: list[dict]) -> httpx.MockTransport:
|
||||
def handle(req: httpx.Request) -> httpx.Response:
|
||||
if req.url.path.endswith("/channels"):
|
||||
return httpx.Response(200, json={"items": [{"contentDetails": {"relatedPlaylists": {"uploads": "UUtest"}}}]})
|
||||
if req.url.path.endswith("/playlistItems"):
|
||||
assert req.url.params["playlistId"] == "UUtest"
|
||||
return httpx.Response(200, json={"items": [{"contentDetails": {"videoId": v["id"]}} for v in videos]})
|
||||
return httpx.Response(200, json={"items": videos})
|
||||
return httpx.MockTransport(handle)
|
||||
|
||||
|
||||
def _video(vid: str, duration: str, published: str, embeddable: bool = True, privacy: str = "public") -> dict:
|
||||
return {"id": vid, "snippet": {"title": f"제목 {vid}", "publishedAt": published}, "contentDetails": {"duration": duration},
|
||||
"status": {"embeddable": embeddable, "privacyStatus": privacy}}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_channel_shorts_keeps_public_embeddable_short_videos_newest_first():
|
||||
videos = [
|
||||
_video("old", "PT30S", "2026-10-20T00:00:00Z"),
|
||||
_video("new", "PT58S", "2026-10-26T00:00:00Z"),
|
||||
_video("long", "PT10M", "2026-10-25T00:00:00Z"),
|
||||
_video("noembed", "PT20S", "2026-10-24T00:00:00Z", embeddable=False),
|
||||
_video("private", "PT20S", "2026-10-23T00:00:00Z", privacy="unlisted"),
|
||||
]
|
||||
async with httpx.AsyncClient(transport=_api(videos)) as client:
|
||||
found = await channel_shorts(client, "key", "UCtest", 10)
|
||||
assert [v["id"] for v in found] == ["new", "old"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_video_title_none_when_embedding_blocked():
|
||||
def handle(req: httpx.Request) -> httpx.Response:
|
||||
if "blocked" in req.url.params["url"]:
|
||||
return httpx.Response(401)
|
||||
return httpx.Response(200, content=json.dumps({"title": "오늘 자전거각"}))
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handle)) as client:
|
||||
assert await video_title(client, "ok") == "오늘 자전거각"
|
||||
assert await video_title(client, "blocked") is None
|
||||
Reference in new issue
Block a user