"""Tests für die Datenmodelle.""" from musiksammlung.models import Album def test_album_folder_name_with_year(): album = Album(artist="Test", album="Mein Album", year=1987, discs=[]) assert album.folder_name == "Mein Album (1987)" def test_album_folder_name_without_year(): album = Album(artist="Test", album="Mein Album", year=None, discs=[]) assert album.folder_name == "Mein Album" def test_sanitize_name(): album = Album(artist='Art:ist', album='Al/bum?', year=None, discs=[]) assert ":" not in album.artist assert "/" not in album.album assert "?" not in album.album def test_album_from_json(): data = { "artist": "Die Toten Hosen", "album": "Opium fürs Volk", "year": 1996, "discs": [ { "disc_number": 1, "tracks": [ {"track_number": 1, "title": "Bonnie & Clyde"}, {"track_number": 2, "title": "Zehn kleine Jägermeister"}, ], } ], } album = Album.model_validate(data) assert album.artist == "Die Toten Hosen" assert len(album.discs) == 1 assert len(album.discs[0].tracks) == 2 assert album.discs[0].tracks[1].title == "Zehn kleine Jägermeister"