fix tests

This commit is contained in:
Georges-Antoine Assi
2025-10-23 17:05:23 -04:00
parent 9fa15d20f0
commit bbade3e40e
8 changed files with 28 additions and 34 deletions

View File

@@ -1,8 +1,7 @@
from typing import Annotated, List, Optional
from typing import Annotated, List
from fastapi import HTTPException, Query, Request, status
from fastapi.responses import Response
from pydantic import BaseModel
from decorators.auth import protected_route
from handler.auth.constants import Scope
@@ -18,11 +17,6 @@ router = APIRouter(
)
class GamelistExportRequest(BaseModel):
platform_ids: List[int]
rom_ids: Optional[List[int]] = None
@protected_route(router.post, "/export", [Scope.ROMS_READ])
async def export_gamelist(
request: Request,

View File

@@ -840,6 +840,7 @@ async def update_rom(
if cleaned_data.get("url_screenshots", []):
path_screenshots = await fs_resource_handler.get_rom_screenshots(
rom=rom,
overwrite=True,
url_screenshots=cleaned_data.get("url_screenshots", []),
)
cleaned_data.update(

View File

@@ -18,8 +18,7 @@ class GamelistExporter:
def _format_release_date(self, timestamp: int) -> str:
"""Format release date to YYYYMMDDTHHMMSS format"""
date = datetime.fromtimestamp(timestamp)
return date.strftime("%Y%m%dT%H%M%S")
return datetime.fromtimestamp(timestamp).strftime("%Y%m%dT%H%M%S")
def _create_game_element(self, rom: Rom, request=None) -> Element:
"""Create a <game> element for a ROM"""
@@ -84,7 +83,8 @@ class GamelistExporter:
)
if rom.metadatum.average_rating is not None:
SubElement(game, "rating").text = f"{rom.metadatum.average_rating:.2f}"
# average_rating in is on a 0-10 scale, but gamelist.xml expects a 0-1 scale
SubElement(game, "rating").text = f"{rom.metadatum.average_rating / 10:.2f}"
if rom.gamelist_id:
SubElement(game, "id").text = str(rom.gamelist_id)

View File

@@ -250,7 +250,6 @@ class GamelistHandler(MetadataHandler):
)
# Build ROM data
rom_media = extract_media_from_gamelist_rom(game)
rom_metadata = extract_metadata_from_gamelist_rom(game)
rom_data = GamelistRom(
gamelist_id=str(uuid.uuid4()),
@@ -266,7 +265,7 @@ class GamelistHandler(MetadataHandler):
)
# Choose which cover style to use
cover_path = rom_media["box2d"]
cover_path = rom_metadata["box2d"]
if cover_path:
cover_path_path = fs_platform_handler.validate_path(
f"{platform_dir}/{cover_path}"
@@ -274,35 +273,35 @@ class GamelistHandler(MetadataHandler):
rom_data["url_cover"] = f"file://{str(cover_path_path)}"
# Grab the manual
if rom_media["manual"]:
if rom_metadata["manual"]:
manual_path = fs_platform_handler.validate_path(
f"{platform_dir}/{rom_media['manual']}"
f"{platform_dir}/{rom_metadata['manual']}"
)
rom_data["url_manual"] = f"file://{str(manual_path)}"
# Build list of screenshot URLs
url_screenshots = []
if rom_media["screenshot"]:
if rom_metadata["screenshot"]:
screenshot_path = fs_platform_handler.validate_path(
f"{platform_dir}/{rom_media['screenshot']}"
f"{platform_dir}/{rom_metadata['screenshot']}"
)
url_screenshots.append(f"file://{str(screenshot_path)}")
if rom_media["title_screen"]:
if rom_metadata["title_screen"]:
title_screen_path = fs_platform_handler.validate_path(
f"{platform_dir}/{rom_media['title_screen']}"
f"{platform_dir}/{rom_metadata['title_screen']}"
)
url_screenshots.append(f"file://{str(title_screen_path)}")
if rom_media["miximage"]:
if rom_metadata["miximage"]:
miximage_path = fs_platform_handler.validate_path(
f"{platform_dir}/{rom_media['miximage']}"
f"{platform_dir}/{rom_metadata['miximage']}"
)
url_screenshots.append(f"file://{str(miximage_path)}")
rom_data["url_screenshots"] = url_screenshots
# TODO: Add support for importing videos
# if rom_media["video"]:
# if rom_metadata["video"]:
# video_path = fs_platform_handler.validate_path(
# f"{platform_dir}/{rom_media['video']}"
# f"{platform_dir}/{rom_metadata['video']}"
# )
# rom_data["url_video"] = f"file://{str(video_path)}")

View File

@@ -315,7 +315,6 @@ def extract_metadata_from_ss_rom(rom: SSGame) -> SSMetadata:
def build_ss_rom(game: SSGame) -> SSRom:
ss_metadata = extract_metadata_from_ss_rom(game)
ss_media = extract_media_from_ss_rom(game)
res_name = ""
for region in get_preferred_regions():
@@ -343,13 +342,13 @@ def build_ss_rom(game: SSGame) -> SSRom:
if res_summary:
break
url_cover = ss_media["box2d"]
url_manual = ss_media["manual"]
url_cover = ss_metadata["box2d"]
url_manual = ss_metadata["manual"]
url_screenshots = pydash.compact(
[
ss_media["screenshot"],
ss_media["title_screen"],
ss_media["miximage"],
ss_metadata["screenshot"],
ss_metadata["title_screen"],
ss_metadata["miximage"],
]
)

View File

@@ -125,10 +125,10 @@ class TestShouldScanRom:
assert result is True
def test_unmatched_scan_with_identified_rom(self, rom: Rom):
"""UNMATCHED should not scan when rom is identified"""
"""UNMATCHED should also scan when rom is identified"""
rom.igdb_id = 1
result = _should_scan_rom(ScanType.UNMATCHED, rom, [])
assert result is False
assert result is True
# Test UPDATE scan type
def test_update_scan_with_no_rom(self):

View File

@@ -257,7 +257,7 @@ class TestFSResourcesHandler:
async def test_get_rom_screenshots_no_rom(self, handler: FSResourcesHandler):
"""Test get_rom_screenshots with no ROM"""
result = await handler.get_rom_screenshots(
None, ["http://example.com/screenshot.jpg"]
None, True, ["http://example.com/screenshot.jpg"]
)
assert result == []
@@ -266,10 +266,10 @@ class TestFSResourcesHandler:
self, handler: FSResourcesHandler, rom: Rom
):
"""Test get_rom_screenshots with no URLs"""
result = await handler.get_rom_screenshots(rom, None)
result = await handler.get_rom_screenshots(rom, True, None)
assert result == []
result = await handler.get_rom_screenshots(rom, [])
result = await handler.get_rom_screenshots(rom, True, [])
assert result == []
@pytest.mark.asyncio
@@ -283,7 +283,7 @@ class TestFSResourcesHandler:
]
with patch.object(handler, "_store_screenshot") as mock_store:
result = await handler.get_rom_screenshots(rom, urls)
result = await handler.get_rom_screenshots(rom, True, urls)
# Should call _store_screenshot for each URL
assert mock_store.call_count == 2

View File

@@ -10,6 +10,7 @@
"metadata-sources": "Sources de métadonnées",
"new-platforms": "Nouvelles plateformes",
"new-platforms-desc": "Scanner uniquement les plateformes récemment ajoutées (plus rapide)",
"no-new-roms": "Aucun nouveau ROMs trouvés",
"not-identified": "Non identifié",
"platforms-scanned-n": "Plateformes : {n} scannée | Plateformes : {n} scannées",
"platforms-scanned-with-details": "Plateformes : {n_scanned_platforms} scannées sur {n_total_platforms}, avec {n_new_platforms} nouvelles et {n_identified_platforms} identifiées",