35 lines
853 B
Python
35 lines
853 B
Python
from pathlib import Path
|
|
from journal_bot.state import State
|
|
|
|
|
|
def test_state_initial_values(tmp_path):
|
|
s = State(tmp_path)
|
|
assert s.last_update_id == 0
|
|
assert not s.has_processed(123)
|
|
|
|
|
|
def test_state_persists_last_update_id(tmp_path):
|
|
s = State(tmp_path)
|
|
s.set_last_update_id(456)
|
|
s2 = State(tmp_path)
|
|
assert s2.last_update_id == 456
|
|
|
|
|
|
def test_state_processed_ids_rolling_window(tmp_path):
|
|
s = State(tmp_path, processed_ids_max=3)
|
|
s.mark_processed(1)
|
|
s.mark_processed(2)
|
|
s.mark_processed(3)
|
|
s.mark_processed(4)
|
|
assert not s.has_processed(1) # dropped
|
|
assert s.has_processed(2)
|
|
assert s.has_processed(3)
|
|
assert s.has_processed(4)
|
|
|
|
|
|
def test_state_processed_ids_persist(tmp_path):
|
|
s = State(tmp_path)
|
|
s.mark_processed(42)
|
|
s2 = State(tmp_path)
|
|
assert s2.has_processed(42)
|