mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
Swap the hand-rolled platform picker in MissingFirmwareSection for the shared PlatformSelect, and fold the triplicated firmware builder in the tests into an add_firmware factory fixture. Keep Platform out of list_firmware: the relationship is lazy="joined", so every row also ran Platform's rom_count and fs_size_bytes aggregate subqueries over roms, for data no caller reads. In useTaskCompletion, the resolver already identifies the live wait, so drop the parallel generation counter and the unused cancel export. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""Tests for `GET /api/firmware`."""
|
|
|
|
from fastapi import status
|
|
|
|
|
|
def test_get_firmware_requires_auth(client, firmware):
|
|
response = client.get("/api/firmware")
|
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
|
|
|
|
|
def test_get_firmware_returns_everything_by_default(
|
|
client, access_token, firmware, missing_firmware
|
|
):
|
|
response = client.get(
|
|
"/api/firmware", headers={"Authorization": f"Bearer {access_token}"}
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
names = [f["file_name"] for f in response.json()]
|
|
assert sorted(names) == ["gone.bin", "present.bin"]
|
|
|
|
|
|
def test_get_firmware_missing_true_returns_only_missing(
|
|
client, access_token, firmware, missing_firmware
|
|
):
|
|
response = client.get(
|
|
"/api/firmware",
|
|
params={"missing": "true"},
|
|
headers={"Authorization": f"Bearer {access_token}"},
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
body = response.json()
|
|
assert [f["file_name"] for f in body] == ["gone.bin"]
|
|
assert body[0]["missing_from_fs"] is True
|
|
|
|
|
|
def test_get_firmware_missing_false_excludes_missing(
|
|
client, access_token, firmware, missing_firmware
|
|
):
|
|
response = client.get(
|
|
"/api/firmware",
|
|
params={"missing": "false"},
|
|
headers={"Authorization": f"Bearer {access_token}"},
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
body = response.json()
|
|
assert [f["file_name"] for f in body] == ["present.bin"]
|
|
assert body[0]["missing_from_fs"] is False
|
|
|
|
|
|
def test_get_firmware_exposes_its_platform(client, access_token, platform, firmware):
|
|
"""The library-wide missing view groups by platform, so the row has to
|
|
carry one without a second round trip per entry."""
|
|
response = client.get(
|
|
"/api/firmware", headers={"Authorization": f"Bearer {access_token}"}
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
assert response.json()[0]["platform_id"] == platform.id
|
|
|
|
|
|
def test_get_firmware_missing_filter_stacks_with_platform_id(
|
|
client, access_token, platform, firmware, missing_firmware
|
|
):
|
|
response = client.get(
|
|
"/api/firmware",
|
|
params={"platform_id": platform.id, "missing": "true"},
|
|
headers={"Authorization": f"Bearer {access_token}"},
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
assert [f["file_name"] for f in response.json()] == ["gone.bin"]
|