mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
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:
37
backend/tests/adapters/services/test_igdb.py
Normal file
37
backend/tests/adapters/services/test_igdb.py
Normal 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}]
|
||||
Reference in New Issue
Block a user