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
This commit is contained in:
Claude
2026-06-07 12:16:02 +00:00
parent cd41422660
commit 105bca7e68

View File

@@ -0,0 +1,37 @@
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from adapters.services.igdb import IGDBService
class TestIGDBServiceUnit:
"""Unit tests with mocked dependencies."""
@pytest.fixture
def service(self):
"""Create an IGDBService instance for testing."""
return IGDBService(twitch_auth=MagicMock())
@pytest.mark.asyncio
async def test_request_acquires_rate_limiter(self, service, monkeypatch):
"""Test that the request reserves a rate-limiter slot before sending."""
acquire_mock = AsyncMock()
monkeypatch.setattr(
"adapters.services.igdb._rate_limiter.acquire", acquire_mock
)
mock_session = AsyncMock()
mock_response = MagicMock()
mock_response.json = AsyncMock(return_value=[{"id": 1}])
mock_response.raise_for_status.return_value = None
mock_session.post.return_value = mock_response
mock_context = MagicMock()
mock_context.get.return_value = mock_session
with patch("adapters.services.igdb.ctx_aiohttp_session", mock_context):
result = await service._request("https://api.igdb.com/v4/games")
acquire_mock.assert_awaited_once()
assert result == [{"id": 1}]