Align balldontlie OpenAPI integration and clarify search metric semantics

This commit is contained in:
Alfredo Di Stasio
2026-03-12 16:37:02 +01:00
parent c9dd10a438
commit dac63f9148
16 changed files with 1562 additions and 82 deletions

View File

@ -40,7 +40,7 @@ class _FakeSession:
class _FakeBalldontlieClient:
def get_json(self, path: str, *, params: dict[str, Any] | None = None) -> dict[str, Any]:
if path == "teams":
if path == "/nba/v1/teams":
return {
"data": [
{
@ -60,7 +60,7 @@ class _FakeBalldontlieClient:
per_page: int = 100,
page_limit: int = 1,
) -> list[dict[str, Any]]:
if path == "players":
if path == "/nba/v1/players":
return [
{
"id": 237,
@ -70,10 +70,7 @@ class _FakeBalldontlieClient:
"team": {"id": 14},
}
]
if path == "stats":
requested_ids = (params or {}).get("game_ids[]") or []
if requested_ids and 9902 not in requested_ids:
return []
if path == "/nba/v1/stats":
return [
{
"pts": 20,
@ -88,7 +85,7 @@ class _FakeBalldontlieClient:
"min": "35:12",
"player": {"id": 237},
"team": {"id": 14},
"game": {"id": 9901, "season": 2024},
"game": {"season": 2024},
},
{
"pts": 30,
@ -103,14 +100,9 @@ class _FakeBalldontlieClient:
"min": "33:00",
"player": {"id": 237},
"team": {"id": 14},
"game": {"id": 9902, "season": 2024},
"game": {"season": 2024},
},
]
if path == "games":
return [
{"id": 9901, "season": 2024},
{"id": 9902, "season": 2024},
]
return []
@ -179,7 +171,7 @@ def test_balldontlie_map_seasons_marks_latest_as_current():
def test_balldontlie_adapter_degrades_when_stats_unauthorized(settings):
class _UnauthorizedStatsClient(_FakeBalldontlieClient):
def list_paginated(self, path: str, *, params=None, per_page=100, page_limit=1):
if path == "stats":
if path == "/nba/v1/stats":
raise ProviderUnauthorizedError(
provider="balldontlie",
path="stats",
@ -266,6 +258,6 @@ def test_balldontlie_client_cursor_pagination(settings):
rows = client.list_paginated("players", per_page=1, page_limit=5)
assert rows == [{"id": 1}, {"id": 2}]
assert session.calls[0]["params"]["page"] == 1
assert "page" not in session.calls[0]["params"]
assert "cursor" not in session.calls[0]["params"]
assert session.calls[1]["params"]["cursor"] == 101