progress.py setzt docs/progress-sync.md um (read_at in Serverzeit mit Uhrversatz, sent_at beim
Senden, force, Warteschlange je Buch, Neuanwendung nach dem Abgleich; dieselben Regeln wie
Ops.kt/ops.js). Der Reader speichert nur, was der Leser bewegt hat; wiederherstellen,
Umbruch und Sprünge schreiben nichts. Neuere Stellen anderer Geräte werden angeboten
("Auf X weitergelesen – springen?"), nie von allein angewendet; "w" springt zur weitesten
Stelle. Fortschritt als Textanteil in Zeichen statt 0.0.
Abgleich über GET /books/ (ohne Markierungs-Blobs), Bücher erst beim Öffnen geladen
(☁ in der Liste). `diora-tui login` meldet wie die Apps an, liest den vorhandenen Token,
leitet den Schlüssel aus dem Passwort ab und speichert beides geschützt (DPAPI).
DIORA_TUI_HOME legt alle Dateien in einen Ordner (platformdirs folgt unter Windows den
Umgebungsvariablen nicht). 35 Tests, tools/smoke_server.py gegen einen lokalen Server.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
"""flush_pending / sync_library against a stubbed API (the server side is covered by the real
|
|
local server in tools/smoke_server.py)."""
|
|
import pytest
|
|
import requests
|
|
|
|
from diora_tui import api, progress, remote
|
|
from diora_tui.config import RemoteConfig
|
|
|
|
T = 1_760_000_000_000
|
|
CFG = RemoteConfig("http://x", "tok", "key")
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def fresh_store(tmp_path, monkeypatch):
|
|
store = progress.ProgressStore(tmp_path / "p.json")
|
|
monkeypatch.setattr(progress, "_default", store)
|
|
return store
|
|
|
|
|
|
def test_flush_sends_read_at_and_device_and_clears_the_queue(fresh_store, monkeypatch):
|
|
fresh_store.write("s7", "3:0.5", 0.25, T, now=T)
|
|
sent = []
|
|
|
|
def fake_post(server, token, book_id, **kw):
|
|
sent.append((book_id, kw))
|
|
return {"ok": True, "stored": True, "read_at": T, "position_anchor": "3:0.5", "scroll_fraction": 0.25, "server_now": T}
|
|
|
|
monkeypatch.setattr(api, "post_progress", fake_post)
|
|
assert remote.flush_pending(CFG) == 1
|
|
assert sent == [(7, {"anchor": "3:0.5", "fraction": 0.25, "read_at": T, "device": "diora TUI", "force": False})]
|
|
assert fresh_store.get("s7").pending is None
|
|
|
|
|
|
def test_flush_keeps_the_queue_when_offline(fresh_store, monkeypatch):
|
|
fresh_store.write("s7", "3:0.5", 0.25, T, now=T)
|
|
|
|
def offline(*a, **kw):
|
|
raise requests.ConnectionError("no network")
|
|
|
|
monkeypatch.setattr(api, "post_progress", offline)
|
|
assert remote.flush_pending(CFG) == 0
|
|
assert fresh_store.get("s7").pending is not None
|
|
|
|
|
|
def test_flush_drops_the_queue_of_a_deleted_book(fresh_store, monkeypatch):
|
|
fresh_store.write("s7", "3:0.5", 0.25, T, now=T)
|
|
|
|
def gone(*a, **kw):
|
|
raise api.ApiError("Buch 7 nicht gefunden (gelöscht oder anderes Konto?)")
|
|
|
|
monkeypatch.setattr(api, "post_progress", gone)
|
|
remote.flush_pending(CFG)
|
|
assert fresh_store.get("s7").pending is None
|
|
|
|
|
|
def test_flush_ignores_local_books(fresh_store, monkeypatch):
|
|
fresh_store.write("abcdef0123456789", "3:0.5", 0.25, T, now=T) # queue=True by default, but not a server key
|
|
monkeypatch.setattr(api, "post_progress", lambda *a, **k: pytest.fail("must not be sent"))
|
|
assert remote.flush_pending(CFG) == 0
|