mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
Labels and the file size read as plain chips now: the tag and weight glyphs said nothing the text did not. In the resume preview the size also outranked the labels and the slot while being the least telling fact about a save, so it drops to the same quiet treatment the list rows already give it. `normalize_asset_labels` gains direct unit tests. It is a pure function, so this covers the trimming, the case-insensitive dedupe and both caps without a database, where the endpoint tests need one. `AssetList` gains two regression tests for the fold count, which the simplify pass rewrote: one asserts only the truly hidden version is counted, the other that no fold is offered when every version is pinned on screen. The i18n stub now keeps the pluralisation count so a wrong one fails. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
"""Tests for utils.assets helpers."""
|
|
|
|
import pytest
|
|
from fastapi import HTTPException, status
|
|
|
|
from models.assets import ASSET_LABEL_MAX_LENGTH, ASSET_LABELS_MAX
|
|
from utils.assets import normalize_asset_labels
|
|
|
|
|
|
def test_labels_are_trimmed_and_blanks_dropped():
|
|
assert normalize_asset_labels([" 100% run ", "", " ", "seed 42"]) == [
|
|
"100% run",
|
|
"seed 42",
|
|
]
|
|
|
|
|
|
def test_labels_dedupe_case_insensitively_keeping_the_first_spelling():
|
|
assert normalize_asset_labels(["Run", "run", "RUN", "Seed"]) == ["Run", "Seed"]
|
|
|
|
|
|
def test_label_order_is_preserved():
|
|
assert normalize_asset_labels(["z", "a", "m"]) == ["z", "a", "m"]
|
|
|
|
|
|
def test_an_empty_list_stays_empty():
|
|
assert normalize_asset_labels([]) == []
|
|
|
|
|
|
def test_a_label_of_exactly_the_maximum_length_is_kept():
|
|
label = "y" * ASSET_LABEL_MAX_LENGTH
|
|
assert normalize_asset_labels([label]) == [label]
|
|
|
|
|
|
def test_an_overlong_label_is_rejected():
|
|
with pytest.raises(HTTPException) as exc:
|
|
normalize_asset_labels(["fine", "x" * (ASSET_LABEL_MAX_LENGTH + 1)])
|
|
|
|
assert exc.value.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
|
|
|
|
|
|
def test_the_maximum_number_of_labels_is_kept():
|
|
labels = [f"label {i}" for i in range(ASSET_LABELS_MAX)]
|
|
assert normalize_asset_labels(labels) == labels
|
|
|
|
|
|
def test_too_many_labels_are_rejected():
|
|
with pytest.raises(HTTPException) as exc:
|
|
normalize_asset_labels([f"label {i}" for i in range(ASSET_LABELS_MAX + 1)])
|
|
|
|
assert exc.value.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
|
|
|
|
|
|
def test_duplicates_beyond_the_cap_collapse_instead_of_being_rejected():
|
|
"""The cap counts what is stored, so repeats of one label are not a breach."""
|
|
assert normalize_asset_labels(["same"] * (ASSET_LABELS_MAX + 10)) == ["same"]
|