Skip to content

Commit 105bca7

Browse files
committed
Add IGDBService rate-limiter unit test
The IGDB service acquires a rate-limiter slot before each request like the other metadata services, but unlike them had no direct unit test asserting it (IGDB is otherwise exercised via cassette-backed handler tests). Add a focused test so the limiter call can't be silently removed or moved after the request. https://claude.ai/code/session_01133QQuWvq8Zm25DZMP9PVr
1 parent cd41422 commit 105bca7

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from unittest.mock import AsyncMock, MagicMock, patch
2+
3+
import pytest
4+
5+
from adapters.services.igdb import IGDBService
6+
7+
8+
class TestIGDBServiceUnit:
9+
"""Unit tests with mocked dependencies."""
10+
11+
@pytest.fixture
12+
def service(self):
13+
"""Create an IGDBService instance for testing."""
14+
return IGDBService(twitch_auth=MagicMock())
15+
16+
@pytest.mark.asyncio
17+
async def test_request_acquires_rate_limiter(self, service, monkeypatch):
18+
"""Test that the request reserves a rate-limiter slot before sending."""
19+
acquire_mock = AsyncMock()
20+
monkeypatch.setattr(
21+
"adapters.services.igdb._rate_limiter.acquire", acquire_mock
22+
)
23+
24+
mock_session = AsyncMock()
25+
mock_response = MagicMock()
26+
mock_response.json = AsyncMock(return_value=[{"id": 1}])
27+
mock_response.raise_for_status.return_value = None
28+
mock_session.post.return_value = mock_response
29+
30+
mock_context = MagicMock()
31+
mock_context.get.return_value = mock_session
32+
33+
with patch("adapters.services.igdb.ctx_aiohttp_session", mock_context):
34+
result = await service._request("https://api.igdb.com/v4/games")
35+
36+
acquire_mock.assert_awaited_once()
37+
assert result == [{"id": 1}]

0 commit comments

Comments
 (0)