feat(harness): manifest archived/group fields + session mutation helpers
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
"""Tests for session manifest mutations (rename, group, archive, delete)."""
|
||||
import pytest
|
||||
|
||||
from tht.config import DatabaseConfig
|
||||
from tht.session.store import (
|
||||
SessionError,
|
||||
create_session,
|
||||
delete_session,
|
||||
load_session,
|
||||
set_archived,
|
||||
set_group,
|
||||
set_name,
|
||||
)
|
||||
|
||||
|
||||
def _db():
|
||||
return DatabaseConfig(
|
||||
database="testdb", user="u", password="p", # noqa: S106
|
||||
**{"schema": "public"},
|
||||
)
|
||||
|
||||
|
||||
def test_manifest_defaults(tmp_path):
|
||||
m = create_session("domanda", _db(), tmp_path)
|
||||
assert m.archived is False
|
||||
assert m.group is None
|
||||
assert m.name is None
|
||||
|
||||
|
||||
def test_set_name(tmp_path):
|
||||
m = create_session("domanda", _db(), tmp_path)
|
||||
set_name(m.id, "Pazienti 2024", tmp_path)
|
||||
assert load_session(m.id, tmp_path).name == "Pazienti 2024"
|
||||
|
||||
|
||||
def test_set_name_empty_clears(tmp_path):
|
||||
m = create_session("domanda", _db(), tmp_path)
|
||||
set_name(m.id, "x", tmp_path)
|
||||
set_name(m.id, "", tmp_path)
|
||||
assert load_session(m.id, tmp_path).name is None
|
||||
|
||||
|
||||
def test_set_group_and_clear(tmp_path):
|
||||
m = create_session("domanda", _db(), tmp_path)
|
||||
set_group(m.id, "Aritmologia", tmp_path)
|
||||
assert load_session(m.id, tmp_path).group == "Aritmologia"
|
||||
set_group(m.id, "", tmp_path)
|
||||
assert load_session(m.id, tmp_path).group is None
|
||||
|
||||
|
||||
def test_set_archived(tmp_path):
|
||||
m = create_session("domanda", _db(), tmp_path)
|
||||
set_archived(m.id, True, tmp_path)
|
||||
assert load_session(m.id, tmp_path).archived is True
|
||||
set_archived(m.id, False, tmp_path)
|
||||
assert load_session(m.id, tmp_path).archived is False
|
||||
|
||||
|
||||
def test_delete_session(tmp_path):
|
||||
m = create_session("domanda", _db(), tmp_path)
|
||||
delete_session(m.id, tmp_path)
|
||||
assert not (tmp_path / m.id).exists()
|
||||
with pytest.raises(SessionError):
|
||||
load_session(m.id, tmp_path)
|
||||
|
||||
|
||||
def test_delete_missing_raises(tmp_path):
|
||||
with pytest.raises(SessionError):
|
||||
delete_session("nope", tmp_path)
|
||||
Reference in New Issue
Block a user