aboutsummaryrefslogtreecommitdiff
path: root/pocketbook/tests/test_store.py
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-26 14:05:40 -0500
committerCraig Jennings <c@cjennings.net>2026-05-26 14:05:40 -0500
commit70e89e946cbdff307284d11a46558161f713607c (patch)
treec305ce9249fac0aef1318f5caabae0df31be7e95 /pocketbook/tests/test_store.py
parent92f4a9394ae1b662d037a3016e94058a3881bdb8 (diff)
downloadarchsetup-70e89e946cbdff307284d11a46558161f713607c.tar.gz
archsetup-70e89e946cbdff307284d11a46558161f713607c.zip
refactor: fold pocketbook in-tree and drop its install steps
Pocketbook is nowhere near ready, so I pulled it back from publication: deleted the github mirror and the cjennings.net repo, removed the server mirror hook, and copied the package into pocketbook/ here until it's ready to spin back out. Dropped the steps that provisioned it on a fresh install: the gtk4-layer-shell dep and the pip install in archsetup, and the clone in post-install.sh. That clone pointed at the now-deleted github repo, so it would have failed a fresh run regardless. Re-wiring the install is tracked in the pocketbook backlog.
Diffstat (limited to 'pocketbook/tests/test_store.py')
-rw-r--r--pocketbook/tests/test_store.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/pocketbook/tests/test_store.py b/pocketbook/tests/test_store.py
new file mode 100644
index 0000000..fab5bd6
--- /dev/null
+++ b/pocketbook/tests/test_store.py
@@ -0,0 +1,103 @@
+import pytest
+from pocketbook.store import NoteStore
+from pocketbook.note import Note
+
+
+class TestNoteStoreCreate:
+ def test_create_note(self, notes_dir):
+ store = NoteStore(notes_dir)
+ filename = store.create("My Title", "My Body")
+ assert (notes_dir / filename).exists()
+ content = (notes_dir / filename).read_text()
+ assert content == "My Title\n\nMy Body"
+
+ def test_create_assigns_incrementing_order(self, notes_dir):
+ store = NoteStore(notes_dir)
+ f1 = store.create("First", "")
+ f2 = store.create("Second", "")
+ assert Note.parse_order(f1) == 1
+ assert Note.parse_order(f2) == 2
+
+ def test_create_auto_creates_directory(self, tmp_path):
+ d = tmp_path / "nonexistent" / "pocketbook"
+ store = NoteStore(d)
+ filename = store.create("Test", "body")
+ assert d.exists()
+ assert (d / filename).exists()
+
+
+class TestNoteStoreList:
+ def test_list_empty(self, notes_dir):
+ # Remove the sample file if any fixture created one
+ for f in notes_dir.iterdir():
+ f.unlink()
+ store = NoteStore(notes_dir)
+ assert store.list_notes() == []
+
+ def test_list_returns_sorted_by_order(self, notes_dir):
+ (notes_dir / "0002-20260101-120000-abc12.txt").write_text("B\n\nbody b")
+ (notes_dir / "0001-20260101-120000-def34.txt").write_text("A\n\nbody a")
+ (notes_dir / "0003-20260101-120000-ghi56.txt").write_text("C\n\nbody c")
+ store = NoteStore(notes_dir)
+ notes = store.list_notes()
+ assert len(notes) == 3
+ assert notes[0][1].title == "A"
+ assert notes[1][1].title == "B"
+ assert notes[2][1].title == "C"
+
+ def test_list_skips_non_txt_files(self, notes_dir):
+ (notes_dir / "0001-20260101-120000-abc12.txt").write_text("Note\n\nbody")
+ (notes_dir / "README.md").write_text("not a note")
+ store = NoteStore(notes_dir)
+ assert len(store.list_notes()) == 1
+
+ def test_list_skips_corrupted_filenames(self, notes_dir):
+ (notes_dir / "0001-20260101-120000-abc12.txt").write_text("Good\n\nbody")
+ (notes_dir / "bad-name.txt").write_text("Bad\n\nbody")
+ store = NoteStore(notes_dir)
+ notes = store.list_notes()
+ assert len(notes) == 1
+ assert notes[0][1].title == "Good"
+
+
+class TestNoteStoreUpdate:
+ def test_update_note(self, notes_dir):
+ fname = "0001-20260101-120000-abc12.txt"
+ (notes_dir / fname).write_text("Old Title\n\nOld body")
+ store = NoteStore(notes_dir)
+ store.update(fname, "New Title", "New body")
+ content = (notes_dir / fname).read_text()
+ assert content == "New Title\n\nNew body"
+
+ def test_update_nonexistent_raises(self, notes_dir):
+ store = NoteStore(notes_dir)
+ with pytest.raises(FileNotFoundError):
+ store.update("0099-20260101-120000-nope0.txt", "T", "B")
+
+
+class TestNoteStoreDelete:
+ def test_delete_note(self, notes_dir):
+ fname = "0001-20260101-120000-abc12.txt"
+ (notes_dir / fname).write_text("Delete me\n\nbody")
+ store = NoteStore(notes_dir)
+ store.delete(fname)
+ assert not (notes_dir / fname).exists()
+
+ def test_delete_nonexistent_raises(self, notes_dir):
+ store = NoteStore(notes_dir)
+ with pytest.raises(FileNotFoundError):
+ store.delete("0099-20260101-120000-nope0.txt")
+
+
+class TestNoteStoreReorder:
+ def test_reorder_renumbers_files(self, notes_dir):
+ # Create files with gaps in ordering
+ (notes_dir / "0001-20260101-120000-aaa11.txt").write_text("A\n\na")
+ (notes_dir / "0005-20260101-120000-bbb22.txt").write_text("B\n\nb")
+ (notes_dir / "0010-20260101-120000-ccc33.txt").write_text("C\n\nc")
+ store = NoteStore(notes_dir)
+ store.reorder()
+ notes = store.list_notes()
+ assert Note.parse_order(notes[0][0]) == 1
+ assert Note.parse_order(notes[1][0]) == 2
+ assert Note.parse_order(notes[2][0]) == 3