fix tests

This commit is contained in:
Georges-Antoine Assi
2025-10-21 14:39:45 -04:00
parent aaf3f5364c
commit 653d7851cb
2 changed files with 4 additions and 50 deletions

View File

@@ -1,6 +1,7 @@
from unittest.mock import Mock
import pytest
import socketio
from endpoints.sockets.scan import ScanStats, _should_scan_rom
from handler.scan_handler import ScanType
@@ -37,7 +38,7 @@ def test_scan_stats():
assert stats.new_firmware == 1
def test_merging_scan_stats():
async def test_merging_scan_stats():
stats = ScanStats(
scanned_platforms=1,
new_platforms=2,
@@ -49,7 +50,8 @@ def test_merging_scan_stats():
new_firmware=8,
)
stats.update(
await stats.update(
socket_manager=Mock(spec=socketio.AsyncRedisManager),
scanned_platforms=stats.scanned_platforms + 10,
new_platforms=stats.new_platforms + 11,
identified_platforms=stats.identified_platforms + 12,

View File

@@ -268,54 +268,6 @@ class TestMetadataHandlerMethods:
assert index_entry is not None
assert index_entry["publisher"] == "Nintendo"
@pytest.mark.asyncio
async def test_switch_titledb_format_cache_missing_fetch_success(
self, handler: MetadataHandler
):
"""Test Switch TitleDB format when cache is missing but fetch succeeds."""
with patch.object(
async_cache, "exists", new_callable=AsyncMock
) as mock_exists, patch.object(
async_cache, "hget", new_callable=AsyncMock
) as mock_hget, patch(
"handler.metadata.base_handler.update_switch_titledb_task"
) as mock_task:
# First call returns False (cache missing), second returns True (after fetch)
mock_exists.side_effect = [False, True]
mock_hget.return_value = json.dumps({"name": "Fetched Game"})
mock_task.run = AsyncMock()
match = re.match(SWITCH_TITLEDB_REGEX, "70123456789012")
assert match is not None
result = await handler._switch_titledb_format(match, "original")
mock_task.run.assert_called_once_with(force=True)
assert result[0] == "Fetched Game"
@pytest.mark.asyncio
async def test_switch_titledb_format_cache_missing_fetch_fails(
self, handler: MetadataHandler
):
"""Test Switch TitleDB format when cache is missing and fetch fails."""
with patch.object(
async_cache, "exists", new_callable=AsyncMock
) as mock_exists, patch(
"handler.metadata.base_handler.update_switch_titledb_task"
) as mock_task, patch(
"handler.metadata.base_handler.log"
) as mock_log:
mock_exists.return_value = False # Cache always missing
mock_task.run = AsyncMock()
match = re.match(SWITCH_TITLEDB_REGEX, "70123456789012")
assert match is not None
result = await handler._switch_titledb_format(match, "original")
mock_log.error.assert_called()
assert result == ("original", None)
@pytest.mark.asyncio
async def test_switch_titledb_format_not_found(self, handler: MetadataHandler):
"""Test Switch TitleDB format when title ID not found."""