38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
from app.services.tv_streams import (
|
|
CCTV4_HOMEPAGE,
|
|
CCTV4_STREAM,
|
|
UNSUPPORTED_CCTV4_STREAM,
|
|
normalize_tv_settings,
|
|
normalize_tv_source,
|
|
)
|
|
|
|
|
|
def test_default_keeps_aljazeera_and_does_not_offer_cdrm_as_plain_hls():
|
|
settings = normalize_tv_settings(None)
|
|
assert settings["default_source_id"] == "aljazeera-mubasher"
|
|
cctv = next(source for source in settings["sources"] if source["id"] == "cctv4")
|
|
assert cctv["source_type"] == "hls"
|
|
assert cctv["stream_url"] == CCTV4_STREAM
|
|
assert "美洲版" in cctv["name"]
|
|
assert cctv["use_proxy"] is False
|
|
assert cctv["homepage_url"] == CCTV4_HOMEPAGE
|
|
|
|
|
|
def test_saved_legacy_default_is_corrected_without_mutating_input():
|
|
saved = {"id": "cctv4", "source_type": "hls", "stream_url": UNSUPPORTED_CCTV4_STREAM}
|
|
source = normalize_tv_source(saved)
|
|
assert source["source_type"] == "hls"
|
|
assert source["stream_url"] == CCTV4_STREAM
|
|
assert source["use_proxy"] is False
|
|
assert saved["stream_url"] == UNSUPPORTED_CCTV4_STREAM
|
|
|
|
|
|
def test_custom_cctv_stream_and_fallback_preference_are_preserved():
|
|
custom = {"id": "cctv4", "source_type": "hls", "stream_url": "https://example.com/licensed.m3u8"}
|
|
settings = normalize_tv_settings({"auto_fallback": False, "sources": [custom]})
|
|
source = next(source for source in settings["sources"] if source["id"] == "cctv4")
|
|
assert source["stream_url"] == custom["stream_url"]
|
|
assert source["source_type"] == "hls"
|
|
assert source["use_proxy"] is True
|
|
assert settings["auto_fallback"] is False
|