From 41c503645122f3d2d79ea4a428d6eb72c399c5b5 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 30 Nov 2026 11:13:47 +0100 Subject: feat(todo): Vikunja tasks due now on the Dashboard A row under the music and spending cards lists the open Vikunja tasks that are due today or overdue, or whose reminder has passed, and is hidden when there are none. A task with a reminder still ahead is left out, so snoozing adds a reminder 30 min ahead and the task returns when it fires. Tap opens the task in the PC's browser, hold marks it done, a swipe right snoozes it. [todo] url points at Vikunja; the API token lives in ~/.config/deck-it/vikunja-token. Co-Authored-By: Claude Opus 5.5 --- tests/test_todo.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/test_todo.py (limited to 'tests/test_todo.py') diff --git a/tests/test_todo.py b/tests/test_todo.py new file mode 100644 index 0000000..f648a36 --- /dev/null +++ b/tests/test_todo.py @@ -0,0 +1,124 @@ +# deck-it - tests for the Vikunja todo module +# Copyright (C) 2026 Danilo M. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + +import tempfile +import unittest +from datetime import datetime, timezone + +from deckit.module import ModuleError +from deckit.modules import todo + +NOW = datetime(2026, 11, 30, 12, 0, tzinfo=timezone.utc) +NONE = "0001-01-01T00:00:00Z" + + +def task(id, due=NONE, reminders=None, title=None): + return {"id": id, "title": title or f"t{id}", "due_date": due, + "reminders": [{"reminder": r} for r in reminders] if reminders else None} + + +class Pick(unittest.TestCase): + def test_future_reminder_hides_a_task(self): + got = todo.pick([task(1, due="2026-11-29T09:00:00Z", reminders=["2026-11-30T12:30:00Z"]), + task(2, reminders=["2026-11-30T11:00:00Z"])], NOW) + self.assertEqual([t["id"] for t in got], [2]) + + def test_overdue_first_then_by_due_then_reminder_only(self): + got = todo.pick([task(1, reminders=["2026-11-30T08:00:00Z"]), + task(2, due="2026-11-30T18:00:00Z"), + task(3, due="2026-11-28T09:00:00Z")], NOW) + self.assertEqual([t["id"] for t in got], [3, 2, 1]) + + def test_year_one_reads_as_no_due_date(self): + self.assertIsNone(todo.pick([task(1, reminders=["2026-11-30T08:00:00Z"])], NOW)[0]["due"]) + self.assertEqual(todo.pick([task(2, due="2026-11-30T18:00:00Z")], NOW)[0]["due"], + "2026-11-30T18:00:00Z") + + +class Fake: + def __init__(self, tasks): + self.tasks, self.calls = tasks, [] + + def __call__(self, method, url, token, data=None): + self.calls.append((method, url, data)) + if url.endswith("/api/v1/info"): + return {"frontend_url": "http://vikunja.example.org/"} + if method == "GET" and "/api/v2/tasks?" in url: + return {"items": self.tasks} + if method == "GET": + return next(t for t in self.tasks if url.endswith(f"/tasks/{t['id']}")) + return {} + + +class Module(unittest.TestCase): + def setUp(self): + self.dir = tempfile.TemporaryDirectory() + tok = Path(self.dir.name) / "token" + tok.write_text("secret\n") + self.http = Fake([task(7, due="2026-11-29T09:00:00Z", reminders=["2026-11-29T08:00:00Z"])]) + self.opened = [] + self.m = todo.Todo({"todo": {"url": "http://vikunja.example.org:3456/"}, "http": self.http, + "token": tok, "popen": self.opened.append, "now": lambda: NOW}) + self.m.refresh() + + def tearDown(self): + self.dir.cleanup() + + def test_state_lists_tasks(self): + st = self.m.state() + self.assertEqual([t["id"] for t in st["tasks"]], [7]) + self.assertIsNone(st["error"]) + + def test_unlisted_id_is_refused(self): + for act in ("open", "done", "snooze"): + with self.assertRaises(ModuleError): + self.m.actions[act]({"id": 8}) + + def test_open_runs_xdg_open_on_the_task(self): + self.m.actions["open"]({"id": 7}) + self.assertEqual(self.opened, [["xdg-open", "http://vikunja.example.org/tasks/7"]]) + + def test_done_patches_only_done(self): + self.m.actions["done"]({"id": 7}) + self.assertIn(("PATCH", "http://vikunja.example.org:3456/api/v2/tasks/7", {"done": True}), + self.http.calls) + + def test_snooze_keeps_old_reminders_and_adds_one(self): + self.m.actions["snooze"]({"id": 7}) + patch = [c for c in self.http.calls if c[0] == "PATCH"][-1] + self.assertEqual(patch[2], {"reminders": [{"reminder": "2026-11-29T08:00:00Z"}, + {"reminder": "2026-11-30T12:30:00Z"}]}) + + def test_error_is_reported(self): + def down(*a, **k): + raise OSError("connection refused") + self.m.http = down + self.m.refresh() + self.assertEqual(self.m.state(), {"tasks": [], "error": "connection refused"}) + + def test_empty_url_is_quiet(self): + m = todo.make({"todo": {"url": ""}}) + self.assertEqual(m.state(), {"tasks": [], "error": None}) + self.assertEqual(m.actions, {}) + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3