51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from server.services.dramabox.locales import film_path, public_list, resolve
|
|
from server.services.dramabox.playlist import _choose_src
|
|
from server.services.playlist import is_direct_media
|
|
|
|
|
|
def test_locales_and_film_path() -> None:
|
|
items = public_list()
|
|
ids = [item["id"] for item in items]
|
|
assert "th" in ids
|
|
assert "en" in ids
|
|
assert "zhHans" in ids
|
|
thai = resolve("th")
|
|
assert thai["country"] == "泰国"
|
|
assert thai["language"] == "泰语"
|
|
assert film_path("en", "41000119953") == "/film/41000119953"
|
|
assert film_path("th", "41000119953") == "/th/film/41000119953"
|
|
try:
|
|
resolve("xx")
|
|
except RuntimeError as exc:
|
|
assert "语言" in str(exc)
|
|
else:
|
|
raise AssertionError("未知语言应拒绝")
|
|
|
|
|
|
def test_chapter_source_choice() -> None:
|
|
src, kind = _choose_src({
|
|
"m3u8Url": "https://cdn.example/ep1.m3u8?sig=1",
|
|
"mp4": "https://cdn.example/ep1.mp4?sig=1",
|
|
"unlock": True,
|
|
})
|
|
assert kind == "hls"
|
|
assert src.endswith(".m3u8?sig=1")
|
|
|
|
src, kind = _choose_src({
|
|
"m3u8Url": "",
|
|
"mp4": "https://cdn.example/ep2.mp4?sig=1",
|
|
"unlock": True,
|
|
})
|
|
assert kind == "file"
|
|
assert is_direct_media(src)
|
|
|
|
src, kind = _choose_src({"unlock": False})
|
|
assert src == ""
|
|
assert kind == ""
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_locales_and_film_path()
|
|
test_chapter_source_choice()
|
|
print("ok")
|