Add the ability to choose the database path at startup. Add more tests. Add bandit
This commit is contained in:
parent
8c7226964a
commit
6bc5b66d3f
16 changed files with 297 additions and 97 deletions
|
|
@ -6,17 +6,30 @@ from bouquin.settings import (
|
|||
from bouquin.db import DBConfig
|
||||
|
||||
|
||||
def test_load_and_save_db_config_roundtrip(app, tmp_path):
|
||||
def _clear_db_settings():
|
||||
s = get_settings()
|
||||
for k in ["db/path", "db/key", "ui/idle_minutes", "ui/theme", "ui/move_todos"]:
|
||||
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)
|
||||
|
||||
|
|
@ -26,3 +39,21 @@ def test_load_and_save_db_config_roundtrip(app, tmp_path):
|
|||
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) == ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue