aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_todo.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-30 11:18:32 +0100
committerDanilo M. <danix@danix.xyz>2026-11-30 11:18:32 +0100
commit202995fc8afab753a9e5c441932779c9a5249c96 (patch)
treefe051c09097e965c7e49f1ccebce3c270d34b415 /tests/test_todo.py
parent41c503645122f3d2d79ea4a428d6eb72c399c5b5 (diff)
downloaddeck-it-202995fc8afab753a9e5c441932779c9a5249c96.tar.gz
deck-it-202995fc8afab753a9e5c441932779c9a5249c96.zip
feat(todo): read the Vikunja token from pass
[todo] pass names the pass entry holding the API token; it is read once and kept in memory, and read again after Vikunja answers 401. No token file on disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_todo.py')
-rw-r--r--tests/test_todo.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/tests/test_todo.py b/tests/test_todo.py
index f648a36..9307012 100644
--- a/tests/test_todo.py
+++ b/tests/test_todo.py
@@ -19,7 +19,6 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
-import tempfile
import unittest
from datetime import datetime, timezone
@@ -58,7 +57,7 @@ class Fake:
self.tasks, self.calls = tasks, []
def __call__(self, method, url, token, data=None):
- self.calls.append((method, url, data))
+ self.calls.append((method, url, data, token))
if url.endswith("/api/v1/info"):
return {"frontend_url": "http://vikunja.example.org/"}
if method == "GET" and "/api/v2/tasks?" in url:
@@ -70,17 +69,32 @@ class Fake:
class Module(unittest.TestCase):
def setUp(self):
- self.dir = tempfile.TemporaryDirectory()
- tok = Path(self.dir.name) / "token"
- tok.write_text("secret\n")
+ self.entries = []
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 = todo.Todo({"todo": {"url": "http://vikunja.example.org:3456/", "pass": "vikunja/deck-it"},
+ "http": self.http, "pass": lambda e: self.entries.append(e) or "secret",
+ "popen": self.opened.append, "now": lambda: NOW})
self.m.refresh()
- def tearDown(self):
- self.dir.cleanup()
+ def test_token_read_from_pass_once(self):
+ self.m.refresh()
+ self.assertEqual(self.entries, ["vikunja/deck-it"])
+ self.assertEqual({c[3] for c in self.http.calls if "/api/v2/" in c[1]}, {"secret"})
+
+ def test_refused_token_is_read_again(self):
+ def refuse(*a, **k):
+ raise OSError("HTTP 401")
+ http, self.m.http = self.m.http, refuse
+ self.m.refresh()
+ self.m.http = http
+ self.m.refresh()
+ self.assertEqual(len(self.entries), 2)
+
+ def test_no_entry_is_an_error(self):
+ m = todo.Todo({"todo": {"url": "http://vikunja.example.org"}, "http": self.http})
+ m.refresh()
+ self.assertIn("pass", m.state()["error"])
def test_state_lists_tasks(self):
st = self.m.state()
@@ -98,7 +112,7 @@ class Module(unittest.TestCase):
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.assertIn(("PATCH", "http://vikunja.example.org:3456/api/v2/tasks/7", {"done": True}, "secret"),
self.http.calls)
def test_snooze_keeps_old_reminders_and_adds_one(self):