84 lines
3.7 KiB
Python
84 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from biliup_next.core.config import SettingsService
|
|
|
|
|
|
class SettingsServiceTests(unittest.TestCase):
|
|
def test_load_seeds_settings_from_standalone_example_when_missing(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
root = Path(tmpdir)
|
|
config_dir = root / "config"
|
|
config_dir.mkdir(parents=True, exist_ok=True)
|
|
(config_dir / "settings.schema.json").write_text(
|
|
"""
|
|
{
|
|
"groups": {
|
|
"runtime": {
|
|
"database_path": {"type": "string", "default": "data/workspace/biliup_next.db"}
|
|
},
|
|
"paths": {
|
|
"stage_dir": {"type": "string", "default": "data/workspace/stage"},
|
|
"backup_dir": {"type": "string", "default": "data/workspace/backup"},
|
|
"session_dir": {"type": "string", "default": "data/workspace/session"},
|
|
"cookies_file": {"type": "string", "default": "runtime/cookies.json"},
|
|
"upload_config_file": {"type": "string", "default": "runtime/upload_config.json"}
|
|
},
|
|
"ingest": {
|
|
"ffprobe_bin": {"type": "string", "default": "ffprobe"},
|
|
"yt_dlp_cmd": {"type": "string", "default": "yt-dlp"},
|
|
"yt_dlp_format": {"type": "string", "default": ""}
|
|
},
|
|
"transcribe": {
|
|
"ffmpeg_bin": {"type": "string", "default": "ffmpeg"}
|
|
},
|
|
"split": {
|
|
"ffmpeg_bin": {"type": "string", "default": "ffmpeg"}
|
|
},
|
|
"song_detect": {
|
|
"codex_cmd": {"type": "string", "default": "codex"},
|
|
"qwen_cmd": {"type": "string", "default": "qwen"}
|
|
},
|
|
"publish": {
|
|
"biliup_path": {"type": "string", "default": "runtime/biliup"},
|
|
"cookie_file": {"type": "string", "default": "runtime/cookies.json"}
|
|
}
|
|
}
|
|
}
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
(config_dir / "settings.standalone.example.json").write_text(
|
|
"""
|
|
{
|
|
"runtime": {"database_path": "data/workspace/biliup_next.db"},
|
|
"paths": {
|
|
"stage_dir": "data/workspace/stage",
|
|
"backup_dir": "data/workspace/backup",
|
|
"session_dir": "data/workspace/session",
|
|
"cookies_file": "runtime/cookies.json",
|
|
"upload_config_file": "runtime/upload_config.json"
|
|
},
|
|
"ingest": {"ffprobe_bin": "ffprobe", "yt_dlp_cmd": "yt-dlp", "yt_dlp_format": ""},
|
|
"transcribe": {"ffmpeg_bin": "ffmpeg"},
|
|
"split": {"ffmpeg_bin": "ffmpeg"},
|
|
"song_detect": {"codex_cmd": "codex", "qwen_cmd": "qwen"},
|
|
"publish": {"biliup_path": "runtime/biliup", "cookie_file": "runtime/cookies.json"}
|
|
}
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
bundle = SettingsService(root).load()
|
|
|
|
self.assertTrue((config_dir / "settings.json").exists())
|
|
self.assertTrue((config_dir / "settings.staged.json").exists())
|
|
self.assertEqual(bundle.settings["paths"]["cookies_file"], str((root / "runtime" / "cookies.json").resolve()))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|