def test_acquire_tags_from_genre(genre, expected_tags): data = { "title": "Track Title", "artist": "Track Artist", "album": "Track Album", "genre": genre, } expected = { "title": "Track Title", "artists": [{ "name": "Track Artist", "mbid": None }], "album": { "title": "Track Album", "mbid": None, "release_date": None, "artists": [], "cover_data": None, }, } if expected_tags: expected["tags"] = expected_tags serializer = metadata.TrackMetadataSerializer( data=metadata.FakeMetadata(data)) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected
def test_serializer_strict_mode_true(): data = {} serializer = metadata.TrackMetadataSerializer( data=metadata.FakeMetadata(data), context={"strict": True} ) with pytest.raises(metadata.serializers.ValidationError): assert serializer.is_valid(raise_exception=True)
def test_serializer_empty_fields(field_name): data = { "title": "Track Title", "artist": "Track Artist", "album": "Track Album", # empty copyright/license field shouldn't fail, cf #850 field_name: "", } expected = { "title": "Track Title", "artists": [{ "name": "Track Artist", "mbid": None }], "album": { "title": "Track Album", "mbid": None, "release_date": None, "artists": [], "cover_data": None, }, } serializer = metadata.TrackMetadataSerializer( data=metadata.FakeMetadata(data)) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected
def test_serializer_album_artist_missing(): data = { "title": "Peer Gynt Suite no. 1, op. 46: I. Morning", "artist": "Edvard Grieg", "album": "Peer Gynt Suite no. 1, op. 46", } expected = { "title": "Peer Gynt Suite no. 1, op. 46: I. Morning", "artists": [{ "name": "Edvard Grieg", "mbid": None }], "album": { "title": "Peer Gynt Suite no. 1, op. 46", "mbid": None, "release_date": None, "artists": [], "cover_data": None, }, } serializer = metadata.TrackMetadataSerializer( data=metadata.FakeMetadata(data)) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected
def test_fake_metadata_with_serializer(): data = { "title": "Peer Gynt Suite no. 1, op. 46: I. Morning", "artist": "Edvard Grieg", "album_artist": "Edvard Grieg; Musopen Symphony Orchestra", "album": "Peer Gynt Suite no. 1, op. 46", "date": "2012-08-15", "position": "1", "disc_number": "1", "musicbrainz_albumid": "a766da8b-8336-47aa-a3ee-371cc41ccc75", "mbid": "bd21ac48-46d8-4e78-925f-d9cc2a294656", "musicbrainz_artistid": "013c8e5b-d72a-4cd3-8dee-6c64d6125823", "musicbrainz_albumartistid": "013c8e5b-d72a-4cd3-8dee-6c64d6125823;5b4d7d2d-36df-4b38-95e3-a964234f520f", "license": "Dummy license: http://creativecommons.org/licenses/by-sa/4.0/", "copyright": "Someone", "comment": "hello there", } expected = { "title": "Peer Gynt Suite no. 1, op. 46: I. Morning", "description": {"text": "hello there", "content_type": "text/plain"}, "artists": [ { "name": "Edvard Grieg", "mbid": uuid.UUID("013c8e5b-d72a-4cd3-8dee-6c64d6125823"), } ], "album": { "title": "Peer Gynt Suite no. 1, op. 46", "mbid": uuid.UUID("a766da8b-8336-47aa-a3ee-371cc41ccc75"), "release_date": datetime.date(2012, 8, 15), "artists": [ { "name": "Edvard Grieg", "mbid": uuid.UUID("013c8e5b-d72a-4cd3-8dee-6c64d6125823"), }, { "name": "Musopen Symphony Orchestra", "mbid": uuid.UUID("5b4d7d2d-36df-4b38-95e3-a964234f520f"), }, ], "cover_data": None, }, "position": 1, "disc_number": 1, "mbid": uuid.UUID("bd21ac48-46d8-4e78-925f-d9cc2a294656"), "license": "Dummy license: http://creativecommons.org/licenses/by-sa/4.0/", "copyright": "Someone", } serializer = metadata.TrackMetadataSerializer(data=metadata.FakeMetadata(data)) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected
def test_serializer_album_default_title_when_missing_or_empty(data): expected = { "title": "Track", "artists": [{"name": "Artist", "mbid": None}], "album": { "title": metadata.UNKNOWN_ALBUM, "mbid": None, "release_date": None, "artists": [], "cover_data": None, }, } serializer = metadata.TrackMetadataSerializer(data=metadata.FakeMetadata(data)) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected
def test_serializer_strict_mode_false(): data = {} expected = { "artists": [{"name": None, "mbid": None}], "album": { "title": "[Unknown Album]", "mbid": None, "release_date": None, "artists": [], "cover_data": None, }, } serializer = metadata.TrackMetadataSerializer( data=metadata.FakeMetadata(data), context={"strict": False} ) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected