Files
mywhoosh-garmin-sync/tests/test_state.py
Bastian Wagner 8d07939527 Init
2026-05-05 19:26:43 +02:00

45 lines
1.5 KiB
Python

from pathlib import Path
from mywhoosh_garmin_sync.state import ActivityStore
def test_state_transitions_and_hash_lookup(tmp_path: Path):
store = ActivityStore(tmp_path / "state.sqlite3")
store.initialize()
store.record_downloaded(
source_ref="source-1",
title="Ride",
source_url="https://example.test/ride.fit",
raw_path=tmp_path / "raw.fit",
raw_sha256="raw-hash",
)
assert store.get_status("source-1") == "downloaded"
assert store.is_terminal_source("source-1") is False
store.mark_converted(
source_ref="source-1",
converted_path=tmp_path / "converted.fit",
converted_sha256="converted-hash",
patched_field_count=4,
)
assert store.get_status("source-1") == "converted"
assert store.is_uploaded_hash("converted-hash") is False
store.mark_uploaded("source-1", "123")
assert store.get_status("source-1") == "uploaded"
assert store.is_terminal_source("source-1") is True
assert store.is_uploaded_hash("raw-hash") is True
assert store.is_uploaded_hash("converted-hash") is True
def test_failed_activity_can_be_retried(tmp_path: Path):
store = ActivityStore(tmp_path / "state.sqlite3")
store.initialize()
store.record_downloaded("source-1", "Ride", None, tmp_path / "raw.fit", "hash")
store.mark_failed("source-1", "network failed")
assert store.get_status("source-1") == "failed"
assert store.is_terminal_source("source-1") is False