|
4 | 4 | from fastapi import status |
5 | 5 | from fastapi.testclient import TestClient |
6 | 6 |
|
| 7 | +from handler.database import db_rom_handler |
7 | 8 | from handler.filesystem.resources_handler import FSResourcesHandler |
8 | 9 | from handler.filesystem.roms_handler import FSRomsHandler |
9 | 10 | from handler.metadata.flashpoint_handler import FlashpointHandler, FlashpointRom |
|
14 | 15 | from handler.metadata.ra_handler import RAGameRom, RAHandler |
15 | 16 | from handler.metadata.ss_handler import SSHandler, SSRom |
16 | 17 | from models.platform import Platform |
17 | | -from models.rom import Rom |
| 18 | +from models.rom import Rom, RomFile |
| 19 | +from models.user import User |
18 | 20 |
|
19 | 21 | MOCK_IGDB_ID = 11111 |
20 | 22 | MOCK_MOBY_ID = 22222 |
@@ -57,6 +59,73 @@ def test_get_all_roms( |
57 | 59 | items = body["items"] |
58 | 60 | assert len(items) == 1 |
59 | 61 | assert items[0]["id"] == rom.id |
| 62 | + assert items[0]["files"] == [] |
| 63 | + assert items[0]["siblings"] == [] |
| 64 | + |
| 65 | + |
| 66 | +def test_get_all_roms_with_files( |
| 67 | + client: TestClient, access_token: str, rom: Rom, platform: Platform |
| 68 | +): |
| 69 | + db_rom_handler.add_rom_file( |
| 70 | + RomFile( |
| 71 | + rom_id=rom.id, |
| 72 | + file_name="test_rom.zip", |
| 73 | + file_path=f"{platform.slug}/roms", |
| 74 | + file_size_bytes=1024, |
| 75 | + last_modified=1700000000.0, |
| 76 | + ) |
| 77 | + ) |
| 78 | + |
| 79 | + response = client.get( |
| 80 | + "/api/roms", |
| 81 | + headers={"Authorization": f"Bearer {access_token}"}, |
| 82 | + params={"platform_id": platform.id, "with_files": True}, |
| 83 | + ) |
| 84 | + assert response.status_code == status.HTTP_200_OK |
| 85 | + |
| 86 | + item = response.json()["items"][0] |
| 87 | + assert item["id"] == rom.id |
| 88 | + assert len(item["files"]) == 1 |
| 89 | + assert item["files"][0]["file_name"] == "test_rom.zip" |
| 90 | + # with_files alone must not pull in siblings. |
| 91 | + assert item["siblings"] == [] |
| 92 | + |
| 93 | + |
| 94 | +def test_get_all_roms_with_siblings( |
| 95 | + client: TestClient, access_token: str, platform: Platform, admin_user: User |
| 96 | +): |
| 97 | + siblings = [ |
| 98 | + db_rom_handler.add_rom( |
| 99 | + Rom( |
| 100 | + platform_id=platform.id, |
| 101 | + igdb_id=424242, |
| 102 | + name=name, |
| 103 | + slug=slug, |
| 104 | + fs_name=f"{slug}.zip", |
| 105 | + fs_name_no_tags=slug, |
| 106 | + fs_name_no_ext=slug, |
| 107 | + fs_extension="zip", |
| 108 | + fs_path=f"{platform.slug}/roms", |
| 109 | + ) |
| 110 | + ) |
| 111 | + for name, slug in (("Game A", "game_a"), ("Game B", "game_b")) |
| 112 | + ] |
| 113 | + for sibling in siblings: |
| 114 | + db_rom_handler.add_rom_user(rom_id=sibling.id, user_id=admin_user.id) |
| 115 | + |
| 116 | + response = client.get( |
| 117 | + "/api/roms", |
| 118 | + headers={"Authorization": f"Bearer {access_token}"}, |
| 119 | + params={"platform_id": platform.id, "with_siblings": True}, |
| 120 | + ) |
| 121 | + assert response.status_code == status.HTTP_200_OK |
| 122 | + |
| 123 | + items = {item["id"]: item for item in response.json()["items"]} |
| 124 | + rom_a, rom_b = siblings |
| 125 | + assert [s["id"] for s in items[rom_a.id]["siblings"]] == [rom_b.id] |
| 126 | + assert [s["id"] for s in items[rom_b.id]["siblings"]] == [rom_a.id] |
| 127 | + # with_siblings alone must not pull in files. |
| 128 | + assert items[rom_a.id]["files"] == [] |
60 | 129 |
|
61 | 130 |
|
62 | 131 | @patch.object(FSRomsHandler, "rename_fs_rom") |
|
0 commit comments