mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
Metadata providers (ScreenScraper, RetroAchievements, LaunchBox, Flashpoint, gamelist, IGDB) distinguish the publisher from the developer of a game, but RomM amalgamated both into a single `companies` list at ingestion, so the distinction was unrecoverable. This adds `publishers` and `developers` as new, refined fields end to end while keeping `companies` (the merged union) working exactly as before. Backend: - Handlers now emit publishers/developers alongside the unchanged companies list; IGDB requests the involved_companies developer/ publisher flags to split by role. - Migration 0112 adds generated_publishers/generated_developers columns on roms, projects them through the roms_metadata view, mirrors them into roms_facets, and adds publisher/developer virtual-collection types (triggers/functions rebuilt for MariaDB/MySQL + PostgreSQL). - Filters, facets, endpoints, smart collections and the gamelist/pegasus exporters all carry the new fields; exporters prefer the explicit split and fall back to the companies heuristic for un-rescanned ROMs. Frontend (v2): - Shared filter store + API service, gallery filter drawer, URL persistence, game detail display (Developers/Publishers with a Companies fallback), edit dialog, smart-collection criteria, and a publisher/developer "group virtual collections by" option. - Also relabels the confusing "company"->"Developer" group-by option to "Company" now that a proper Developer option exists. Fixes #3518 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
141 lines
4.9 KiB
Python
141 lines
4.9 KiB
Python
"""End-to-end checks for the roms_metadata derivations.
|
|
|
|
roms_metadata is a view over STORED generated columns on ``roms`` (migration
|
|
0098). These tests write raw provider-metadata blobs and assert the values the
|
|
engine derives and exposes through ``Rom.metadatum``, covering the facet
|
|
columns, the rating average, the gamelist date wrapper, and the quoted-string
|
|
date that the old view silently truncated to ``0``.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from handler.database import db_rom_handler
|
|
from models.rom import Rom
|
|
|
|
|
|
def _reload(rom: Rom) -> Rom:
|
|
reloaded = db_rom_handler.get_rom(rom.id)
|
|
assert reloaded is not None
|
|
return reloaded
|
|
|
|
|
|
class TestGeneratedMetadata:
|
|
def test_igdb_derivations(self, rom: Rom):
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{
|
|
"igdb_metadata": {
|
|
"genres": ["Action", "RPG"],
|
|
"franchises": ["Zelda"],
|
|
"game_modes": ["Single player"],
|
|
"total_rating": "80",
|
|
"first_release_date": "1569369600",
|
|
"age_ratings": [{"rating": "E"}, {"rating": "T"}],
|
|
"player_count": "4",
|
|
},
|
|
},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
assert meta.genres == ["Action", "RPG"]
|
|
assert meta.franchises == ["Zelda"]
|
|
assert meta.game_modes == ["Single player"]
|
|
assert meta.age_ratings == ["E", "T"]
|
|
assert meta.player_count == "4"
|
|
assert meta.average_rating == 80.0
|
|
# Quoted-string epoch seconds -> ms. The old view truncated this to 0.
|
|
assert meta.first_release_date == 1569369600000
|
|
|
|
def test_publishers_developers_derivation(self, rom: Rom):
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{
|
|
"ss_metadata": {
|
|
"companies": ["Atari", "Artech Studios"],
|
|
"publishers": ["Atari"],
|
|
"developers": ["Artech Studios"],
|
|
},
|
|
},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
# Raw view order preserved here (the response schema sorts on serialize).
|
|
assert meta.companies == ["Atari", "Artech Studios"]
|
|
assert meta.publishers == ["Atari"]
|
|
assert meta.developers == ["Artech Studios"]
|
|
|
|
def test_publishers_developers_default_empty(self, rom: Rom):
|
|
# companies present but no split fields -> new fields stay empty.
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{"ss_metadata": {"companies": ["Nintendo"]}},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
assert meta.companies == ["Nintendo"]
|
|
assert meta.publishers == []
|
|
assert meta.developers == []
|
|
|
|
def test_rating_average_across_providers(self, rom: Rom):
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{
|
|
"igdb_metadata": {"total_rating": "84"},
|
|
"ss_metadata": {"ss_score": "8"}, # * 10 -> 80
|
|
},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
assert meta.average_rating == 82.0
|
|
|
|
def test_precedence_falls_through_to_gamelist_date(self, rom: Rom):
|
|
# No earlier provider supplies first_release_date, so the gamelist
|
|
# branch (parsed through the immutable UTC wrapper) wins.
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{"gamelist_metadata": {"first_release_date": "20200101T000000"}},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
assert meta.first_release_date == 1577836800000 # 2020-01-01T00:00:00Z
|
|
|
|
def test_gamelist_leap_day_is_accepted(self, rom: Rom):
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{"gamelist_metadata": {"first_release_date": "20240229T000000"}},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
assert meta.first_release_date == 1709164800000 # 2024-02-29T00:00:00Z
|
|
|
|
@pytest.mark.parametrize(
|
|
"release_date",
|
|
[
|
|
"00000000T000000", # what ES/ES-DE/Skyscraper write for "unknown"
|
|
"19700000T000000",
|
|
"20201301T000000",
|
|
"20200230T000000",
|
|
],
|
|
)
|
|
def test_calendar_invalid_gamelist_date_yields_null(
|
|
self, rom: Rom, release_date: str
|
|
):
|
|
# These pass the 8+6 digit regex but are not real dates. The write must
|
|
# succeed rather than raise out of the generated-column expression.
|
|
db_rom_handler.update_rom(
|
|
rom.id,
|
|
{"gamelist_metadata": {"first_release_date": release_date}},
|
|
)
|
|
|
|
meta = _reload(rom).metadatum
|
|
assert meta.first_release_date is None
|
|
|
|
def test_empty_metadata_yields_defaults(self, rom: Rom):
|
|
meta = _reload(rom).metadatum
|
|
assert meta.genres == []
|
|
assert meta.franchises == []
|
|
assert meta.age_ratings == []
|
|
assert meta.player_count == "1"
|
|
assert meta.first_release_date is None
|
|
assert meta.average_rating is None
|