- Config commands (config add/list/remove) to map local audio folders to Kreativ-Tonies via TonieCloud household/tonie ids - tonies list command to look up household/tonie ids - sync command: diff-based upload of new tracks, pruning of removed chapters, and reordering to match local file order (via tonie-api) - Credentials resolved via env vars/CLI flags/prompt, never stored - Unit tests for config persistence and sync planning/apply logic Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from pathlib import Path
|
|
|
|
from toni_sync.config import AppConfig, ToniMapping, load_config, save_config
|
|
|
|
|
|
def test_upsert_adds_new_mapping():
|
|
cfg = AppConfig()
|
|
m = ToniMapping(name="a", household_id="h1", tonie_id="t1", folder="/tmp/a")
|
|
cfg.upsert(m)
|
|
assert cfg.get("a") == m
|
|
|
|
|
|
def test_upsert_replaces_existing_mapping():
|
|
cfg = AppConfig()
|
|
cfg.upsert(ToniMapping(name="a", household_id="h1", tonie_id="t1", folder="/tmp/a"))
|
|
updated = ToniMapping(name="a", household_id="h1", tonie_id="t2", folder="/tmp/a2")
|
|
cfg.upsert(updated)
|
|
assert len(cfg.mappings) == 1
|
|
assert cfg.get("a").tonie_id == "t2"
|
|
|
|
|
|
def test_remove_returns_false_when_missing():
|
|
cfg = AppConfig()
|
|
assert cfg.remove("nope") is False
|
|
|
|
|
|
def test_save_and_load_roundtrip(tmp_path: Path):
|
|
path = tmp_path / "config.yaml"
|
|
cfg = AppConfig()
|
|
cfg.upsert(
|
|
ToniMapping(
|
|
name="peppa",
|
|
household_id="h1",
|
|
tonie_id="t1",
|
|
folder="/tmp/peppa",
|
|
playlist_ref="https://example.com/playlist/1",
|
|
)
|
|
)
|
|
save_config(cfg, path)
|
|
|
|
loaded = load_config(path)
|
|
assert loaded.get("peppa").tonie_id == "t1"
|
|
assert loaded.get("peppa").playlist_ref == "https://example.com/playlist/1"
|
|
|
|
|
|
def test_load_missing_file_returns_empty_config(tmp_path: Path):
|
|
cfg = load_config(tmp_path / "does-not-exist.yaml")
|
|
assert cfg.mappings == []
|