2026-03-21 17:51:36 +01:00
|
|
|
"""Tests for hltb module - part 3 (fetch_hltb_times)."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
2026-05-28 07:21:29 +02:00
|
|
|
from steam_backlog_enforcer.hltb import (
|
2026-03-21 17:51:36 +01:00
|
|
|
HLTBResult,
|
|
|
|
|
fetch_hltb_times,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFetchHltbTimes:
|
|
|
|
|
"""Tests for fetch_hltb_times."""
|
|
|
|
|
|
|
|
|
|
def test_empty(self) -> None:
|
|
|
|
|
assert fetch_hltb_times([]) == []
|
|
|
|
|
|
|
|
|
|
def test_calls_batch(self) -> None:
|
|
|
|
|
mock_result = HLTBResult(
|
|
|
|
|
app_id=440, game_name="TF2", completionist_hours=50.0, similarity=1.0
|
|
|
|
|
)
|
|
|
|
|
with patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.hltb._fetch_batch",
|
2026-03-21 17:51:36 +01:00
|
|
|
return_value=[mock_result],
|
|
|
|
|
):
|
|
|
|
|
results = fetch_hltb_times([(440, "TF2")])
|
|
|
|
|
assert len(results) == 1
|
|
|
|
|
|
|
|
|
|
def test_none_cache(self) -> None:
|
|
|
|
|
with patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.hltb._fetch_batch",
|
2026-03-21 17:51:36 +01:00
|
|
|
return_value=[],
|
|
|
|
|
):
|
|
|
|
|
results = fetch_hltb_times([(440, "TF2")])
|
|
|
|
|
assert results == []
|
|
|
|
|
|
|
|
|
|
def test_explicit_cache(self) -> None:
|
|
|
|
|
with patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.hltb._fetch_batch",
|
2026-03-21 17:51:36 +01:00
|
|
|
return_value=[],
|
|
|
|
|
):
|
|
|
|
|
cache: dict[int, float] = {440: 10.0}
|
|
|
|
|
results = fetch_hltb_times([(440, "TF2")], cache=cache)
|
|
|
|
|
assert results == []
|