test: add tests for get_latest_haiku_or_default

Refs: OPS-65
This commit is contained in:
Christoph J. Scherr 2025-03-23 14:09:26 +01:00
parent 69db48af8b
commit cf48ac8164
No known key found for this signature in database
GPG key ID: 9EB784BB202BB7BB

View file

@ -2,9 +2,10 @@
# pytest fixtures to work # pytest fixtures to work
from __future__ import annotations from __future__ import annotations
from _pytest.mark.structures import store_mark
import pytest # noqa: F401 import pytest # noqa: F401
from senju.haiku import Haiku from senju.haiku import DEFAULT_HAIKU, Haiku
from senju.store_manager import StoreManager # noqa: F401 from senju.store_manager import StoreManager # noqa: F401
@ -42,3 +43,18 @@ def test_load_latest_with_empty_store(temp_data_dir):
store = StoreManager(temp_data_dir / "empty_store.json") store = StoreManager(temp_data_dir / "empty_store.json")
h = store.get_id_of_latest_haiku() h = store.get_id_of_latest_haiku()
assert h is None assert h is None
def test_load_latest_or_default_with_empty(temp_data_dir):
store = StoreManager(temp_data_dir / "load_or_default_empty.json")
haiku = store.get_latest_haiku_or_default()
assert haiku == DEFAULT_HAIKU
def test_load_latest_or_default_with_non_empty(temp_data_dir):
store = StoreManager(temp_data_dir / "load_or_default_not_empty.json")
nonsense_test_haiku = Haiku(["nonsense", "test", "haiku"])
store.save_haiku(nonsense_test_haiku)
haiku = store.get_latest_haiku_or_default()
assert haiku != DEFAULT_HAIKU
assert haiku == nonsense_test_haiku