| 1 |
import pytest |
| 2 |
|
| 3 |
from beetsplug._utils.musicbrainz import MusicBrainzAPI |
| 4 |
|
| 5 |
|
| 6 |
def test_normalize_data(): |
| 7 |
raw_release = { |
| 8 |
"id": "r1", |
| 9 |
"relations": [ |
| 10 |
{ |
| 11 |
"target-type": "artist", |
| 12 |
"type": "vocal", |
| 13 |
"type-id": "0fdbe3c6-7700-4a31-ae54-b53f06ae1cfa", |
| 14 |
"name": "A", |
| 15 |
}, |
| 16 |
{ |
| 17 |
"target-type": "url", |
| 18 |
"type": "streaming", |
| 19 |
"type-id": "b5f3058a-666c-406f-aafb-f9249fc7b122", |
| 20 |
"url": "http://s", |
| 21 |
}, |
| 22 |
{ |
| 23 |
"target-type": "url", |
| 24 |
"type": "purchase for download", |
| 25 |
"type-id": "92777657-504c-4acb-bd33-51a201bd57e1", |
| 26 |
"url": "http://p", |
| 27 |
}, |
| 28 |
{ |
| 29 |
"target-type": "work", |
| 30 |
"type": "performance", |
| 31 |
"type-id": "a3005666-a872-32c3-ad06-98af558e99b0", |
| 32 |
"work": { |
| 33 |
"relations": [ |
| 34 |
{ |
| 35 |
"artist": {"name": "幾田りら"}, |
| 36 |
"target-type": "artist", |
| 37 |
"type": "composer", |
| 38 |
"type-id": "d59d99ea-23d4-4a80-b066-edca32ee158f", |
| 39 |
}, |
| 40 |
{ |
| 41 |
"target-type": "url", |
| 42 |
"type": "lyrics", |
| 43 |
"type-id": "e38e65aa-75e0-42ba-ace0-072aeb91a538", |
| 44 |
"url": { |
| 45 |
"resource": "https://utaten.com/lyric/tt24121002/" |
| 46 |
}, |
| 47 |
}, |
| 48 |
{ |
| 49 |
"artist": {"name": "幾田りら"}, |
| 50 |
"target-type": "artist", |
| 51 |
"type": "lyricist", |
| 52 |
"type-id": "3e48faba-ec01-47fd-8e89-30e81161661c", |
| 53 |
}, |
| 54 |
{ |
| 55 |
"target-type": "url", |
| 56 |
"type": "lyrics", |
| 57 |
"type-id": "e38e65aa-75e0-42ba-ace0-072aeb91a538", |
| 58 |
"url": { |
| 59 |
"resource": "https://www.uta-net.com/song/366579/" |
| 60 |
}, |
| 61 |
}, |
| 62 |
], |
| 63 |
"title": "百花繚乱", |
| 64 |
"type": "Song", |
| 65 |
}, |
| 66 |
}, |
| 67 |
], |
| 68 |
} |
| 69 |
|
| 70 |
assert MusicBrainzAPI._normalize_data(raw_release) == { |
| 71 |
"id": "r1", |
| 72 |
"artist_relations": [ |
| 73 |
{ |
| 74 |
"type": "vocal", |
| 75 |
"type_id": "0fdbe3c6-7700-4a31-ae54-b53f06ae1cfa", |
| 76 |
"name": "A", |
| 77 |
} |
| 78 |
], |
| 79 |
"url_relations": [ |
| 80 |
{ |
| 81 |
"type": "streaming", |
| 82 |
"type_id": "b5f3058a-666c-406f-aafb-f9249fc7b122", |
| 83 |
"url": "http://s", |
| 84 |
}, |
| 85 |
{ |
| 86 |
"type": "purchase for download", |
| 87 |
"type_id": "92777657-504c-4acb-bd33-51a201bd57e1", |
| 88 |
"url": "http://p", |
| 89 |
}, |
| 90 |
], |
| 91 |
"work_relations": [ |
| 92 |
{ |
| 93 |
"type": "performance", |
| 94 |
"type_id": "a3005666-a872-32c3-ad06-98af558e99b0", |
| 95 |
"work": { |
| 96 |
"artist_relations": [ |
| 97 |
{ |
| 98 |
"type": "composer", |
| 99 |
"type_id": "d59d99ea-23d4-4a80-b066-edca32ee158f", |
| 100 |
"artist": {"name": "幾田りら"}, |
| 101 |
}, |
| 102 |
{ |
| 103 |
"type": "lyricist", |
| 104 |
"type_id": "3e48faba-ec01-47fd-8e89-30e81161661c", |
| 105 |
"artist": {"name": "幾田りら"}, |
| 106 |
}, |
| 107 |
], |
| 108 |
"url_relations": [ |
| 109 |
{ |
| 110 |
"type": "lyrics", |
| 111 |
"type_id": "e38e65aa-75e0-42ba-ace0-072aeb91a538", |
| 112 |
"url": { |
| 113 |
"resource": "https://utaten.com/lyric/tt24121002/" |
| 114 |
}, |
| 115 |
}, |
| 116 |
{ |
| 117 |
"type": "lyrics", |
| 118 |
"type_id": "e38e65aa-75e0-42ba-ace0-072aeb91a538", |
| 119 |
"url": { |
| 120 |
"resource": "https://www.uta-net.com/song/366579/" |
| 121 |
}, |
| 122 |
}, |
| 123 |
], |
| 124 |
"title": "百花繚乱", |
| 125 |
"type": "Song", |
| 126 |
}, |
| 127 |
} |
| 128 |
], |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
@pytest.mark.parametrize( |
| 133 |
"field, term, expected", |
| 134 |
[ |
| 135 |
("artist", ' AC/DC + "[Live]" ', r"artist:(ac\/dc \+ \"\[live\]\")"), |
| 136 |
("", "Foo:Bar", r"foo\:bar"), |
| 137 |
("artist", " ", ""), |
| 138 |
], |
| 139 |
) |
| 140 |
def test_format_search_term(field, term, expected): |
| 141 |
assert MusicBrainzAPI.format_search_term(field, term) == expected |