Dalsi kolo vylepesni /remind

This commit is contained in:
lachtan
2026-06-10 09:54:02 +02:00
parent abdfd8c67d
commit 10801da03e
5 changed files with 63 additions and 80 deletions

View File

@@ -7,19 +7,19 @@ SCRIPTS = Path(__file__).parent.parent / "scripts"
sys.path.insert(0, str(SCRIPTS))
from db import get_db, init_db
import remind_edit
import remind_cli
def _run(db_path, argv):
"""Run remind_edit main with a temporary DB path."""
original_db_path = remind_edit.DB_PATH
"""Run remind_cli main with a temporary DB path."""
original_db_path = remind_cli.DB_PATH
try:
remind_edit.DB_PATH = db_path
remind_cli.DB_PATH = db_path
# Patch the module-level DB_PATH used by functions
sys.argv = ["remind_edit.py"] + argv
return remind_edit.main()
sys.argv = ["remind_cli.py"] + argv
return remind_cli.main()
finally:
remind_edit.DB_PATH = original_db_path
remind_cli.DB_PATH = original_db_path
def test_add_list(tmp_path, capsys):
@@ -112,6 +112,20 @@ def test_edit_text(tmp_path, capsys):
assert data["edited"]["text"] == "new text"
def test_edit_text_by_id(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)
_run(db_path, ["add", "--text", "original text", "--cron", "0 9 * * *"])
capsys.readouterr() # clear setup output
ret = _run(db_path, ["edit", "--id", "1", "--text", "renamed"])
captured = capsys.readouterr()
assert ret == 0
data = json.loads(captured.out)
assert data["edited"]["text"] == "renamed"
assert len(data["edited"]["cron"]) == 1
def test_edit_replace_schedules(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)
@@ -259,7 +273,7 @@ def test_delivered_lists_deliveries(tmp_path, capsys):
def test_delivered_defaults_to_today(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)
today = datetime.now(remind_edit.PRAGUE).date().isoformat()
today = datetime.now(remind_cli.PRAGUE).date().isoformat()
conn = get_db(db_path)
try:
conn.execute(