's'
This commit is contained in:
81
d2ypp2/tests/test_youtube_pro_runtime.py
Normal file
81
d2ypp2/tests/test_youtube_pro_runtime.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from src.youtube_pro_runtime import (
|
||||
ensure_youtube_pro_channel_runtime_files,
|
||||
managed_url_config_relpath_for_pm2,
|
||||
managed_youtube_ini_relpath_for_pm2,
|
||||
normalize_youtube_pro_channels,
|
||||
)
|
||||
|
||||
|
||||
class YoutubeProRuntimeTests(unittest.TestCase):
|
||||
def test_normalize_channels_assigns_default_pm2_and_rejects_duplicate_names(self) -> None:
|
||||
rows = normalize_youtube_pro_channels([{"id": "lane2", "name": "Lane 2"}])
|
||||
self.assertEqual(rows[0]["pm2Name"], "youtube2__lane2")
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
normalize_youtube_pro_channels(
|
||||
[
|
||||
{"id": "lane1", "pm2Name": "custom"},
|
||||
{"id": "lane2", "pm2Name": "custom"},
|
||||
]
|
||||
)
|
||||
|
||||
def test_materialize_runtime_files_from_saved_channel_payload(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
config_dir = Path(tmp)
|
||||
handled, errors = ensure_youtube_pro_channel_runtime_files(
|
||||
config_dir,
|
||||
"youtube2__lane2",
|
||||
[
|
||||
{
|
||||
"id": "lane2",
|
||||
"name": "Lane 2",
|
||||
"pm2Name": "youtube2__lane2",
|
||||
"streamKey": "abcd-efgh-ijkl-mnop",
|
||||
"urlLines": "https://live.douyin.com/123456789\n",
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
self.assertTrue(handled)
|
||||
self.assertEqual(errors, [])
|
||||
youtube_ini = (config_dir / managed_youtube_ini_relpath_for_pm2("youtube2__lane2")).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
url_ini = (config_dir / managed_url_config_relpath_for_pm2("youtube2__lane2")).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertIn("key = abcd-efgh-ijkl-mnop", youtube_ini)
|
||||
self.assertIn("https://live.douyin.com/123456789", url_ini)
|
||||
|
||||
def test_materialize_runtime_files_uses_existing_seed_when_channel_fields_blank(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
config_dir = Path(tmp)
|
||||
(config_dir / "youtube.ini").write_text("[youtube]\nkey = legacy-key\nrtmps = 是\n", encoding="utf-8")
|
||||
(config_dir / "URL_config.ini").write_text("https://live.douyin.com/88888888\n", encoding="utf-8")
|
||||
|
||||
handled, errors = ensure_youtube_pro_channel_runtime_files(
|
||||
config_dir,
|
||||
"youtube2__lane3",
|
||||
[{"id": "lane3", "pm2Name": "youtube2__lane3"}],
|
||||
)
|
||||
|
||||
self.assertTrue(handled)
|
||||
self.assertEqual(errors, [])
|
||||
youtube_ini = (config_dir / managed_youtube_ini_relpath_for_pm2("youtube2__lane3")).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
url_ini = (config_dir / managed_url_config_relpath_for_pm2("youtube2__lane3")).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertIn("legacy-key", youtube_ini)
|
||||
self.assertIn("https://live.douyin.com/88888888", url_ini)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user