57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import configparser
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from src.recorder_config import read_recorder_setting
|
|
|
|
|
|
class RecorderConfigTests(unittest.TestCase):
|
|
def test_read_recorder_setting_falls_back_to_shared_cookie(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
config_dir = root / "config"
|
|
config_dir.mkdir()
|
|
shared = config_dir / "config.ini"
|
|
lane = config_dir / "youtube.youtube2__ch_test.ini"
|
|
shared.write_text(
|
|
"\ufeff[Cookie]\n抖音cookie = shared-cookie-value\n",
|
|
encoding="utf-8",
|
|
)
|
|
lane.write_text(
|
|
"\ufeff[youtube]\nkey = test\n\n[Cookie]\n抖音cookie = \n",
|
|
encoding="utf-8",
|
|
)
|
|
value = read_recorder_setting(
|
|
base_dir=root,
|
|
lane_config_file=lane,
|
|
section="Cookie",
|
|
option="抖音cookie",
|
|
default="",
|
|
)
|
|
self.assertEqual(value, "shared-cookie-value")
|
|
|
|
def test_lane_cookie_overrides_shared(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
config_dir = root / "config"
|
|
config_dir.mkdir()
|
|
shared = config_dir / "config.ini"
|
|
lane = config_dir / "youtube.youtube2__ch_test.ini"
|
|
shared.write_text("\ufeff[Cookie]\n抖音cookie = shared\n", encoding="utf-8")
|
|
lane.write_text("\ufeff[Cookie]\n抖音cookie = lane\n", encoding="utf-8")
|
|
value = read_recorder_setting(
|
|
base_dir=root,
|
|
lane_config_file=lane,
|
|
section="Cookie",
|
|
option="抖音cookie",
|
|
default="",
|
|
)
|
|
self.assertEqual(value, "lane")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|