bouquin/tests/test_settings.py
Miguel Jacq 6bc5b66d3f
All checks were successful
CI / test (push) Successful in 3m49s
Lint / test (push) Successful in 29s
Trivy / test (push) Successful in 21s
Add the ability to choose the database path at startup. Add more tests. Add bandit
2025-11-17 15:15:00 +11:00

59 lines
1.4 KiB
Python

from bouquin.settings import (
get_settings,
load_db_config,
save_db_config,
)
from bouquin.db import DBConfig
def _clear_db_settings():
s = get_settings()
for k in [
"db/default_db",
"db/path", # legacy key
"db/key",
"ui/idle_minutes",
"ui/theme",
"ui/move_todos",
"ui/locale",
]:
s.remove(k)
def test_load_and_save_db_config_roundtrip(app, tmp_path):
_clear_db_settings()
cfg = DBConfig(
path=tmp_path / "notes.db",
key="abc123",
idle_minutes=7,
theme="dark",
move_todos=True,
locale="en",
)
save_db_config(cfg)
loaded = load_db_config()
assert loaded.path == cfg.path
assert loaded.key == cfg.key
assert loaded.idle_minutes == cfg.idle_minutes
assert loaded.theme == cfg.theme
assert loaded.move_todos == cfg.move_todos
assert loaded.locale == cfg.locale
def test_load_db_config_migrates_legacy_db_path(app, tmp_path):
_clear_db_settings()
s = get_settings()
legacy_path = tmp_path / "legacy.db"
s.setValue("db/path", str(legacy_path))
cfg = load_db_config()
# Uses the legacy value…
assert cfg.path == legacy_path
# …but also migrates to the new key and clears the old one.
assert s.value("db/default_db", "", type=str) == str(legacy_path)
assert s.value("db/path", "", type=str) == ""