|
16 | 16 |
|
17 | 17 | import os
|
18 | 18 | from functools import partial
|
| 19 | +from urllib.parse import urlparse |
19 | 20 |
|
20 | 21 | import pytest
|
21 | 22 |
|
@@ -224,45 +225,99 @@ def plugin_config(self):
|
224 | 225 | def file_name(self):
|
225 | 226 | return "examplecom/beetssong"
|
226 | 227 |
|
| 228 | + @pytest.fixture |
| 229 | + def response_data(self, url_title, url): |
| 230 | + return { |
| 231 | + "items": [ |
| 232 | + { |
| 233 | + "title": url_title, |
| 234 | + "link": url, |
| 235 | + "displayLink": urlparse(url).netloc, |
| 236 | + } |
| 237 | + ] |
| 238 | + } |
| 239 | + |
| 240 | + @pytest.fixture |
| 241 | + def fetch_lyrics( |
| 242 | + self, backend, requests_mock, response_data, artist, title |
| 243 | + ): |
| 244 | + requests_mock.get(backend.SEARCH_URL, json=response_data) |
| 245 | + requests_mock.real_http = True |
| 246 | + |
| 247 | + return partial(backend.fetch, artist, title) |
| 248 | + |
227 | 249 | @pytest.mark.on_lyrics_update
|
228 | 250 | @pytest.mark.parametrize(
|
229 |
| - "title, url", |
| 251 | + "artist, title, url_title, url", |
230 | 252 | [
|
231 | 253 | *(
|
232 |
| - ("Lady Madonna", url) |
233 |
| - for url in ( |
234 |
| - "http://www.chartlyrics.com/_LsLsZ7P4EK-F-LD4dJgDQ/Lady+Madonna.aspx", # noqa: E501 |
235 |
| - "http://www.absolutelyrics.com/lyrics/view/the_beatles/lady_madonna", # noqa: E501 |
236 |
| - "https://www.letras.mus.br/the-beatles/275/", |
237 |
| - "https://www.lyricsmania.com/lady_madonna_lyrics_the_beatles.html", |
238 |
| - "https://www.lyricsmode.com/lyrics/b/beatles/lady_madonna.html", |
239 |
| - "https://www.paroles.net/the-beatles/paroles-lady-madonna", |
240 |
| - "https://www.songlyrics.com/the-beatles/lady-madonna-lyrics/", |
241 |
| - "https://sweetslyrics.com/the-beatles/lady-madonna-lyrics", |
242 |
| - "https://www.musica.com/letras.asp?letra=59862", |
243 |
| - "https://www.lacoccinelle.net/259956-the-beatles-lady-madonna.html", |
| 254 | + ("The Beatles", "Lady Madonna", url_title, url) |
| 255 | + for url_title, url in ( |
| 256 | + ( |
| 257 | + "The Beatles Lady Madonna lyrics", |
| 258 | + "http://www.chartlyrics.com/_LsLsZ7P4EK-F-LD4dJgDQ/Lady+Madonna.aspx", |
| 259 | + ), |
| 260 | + ( |
| 261 | + "Lady Madonna Lyrics :: The Beatles - Absolute Lyrics", |
| 262 | + "http://www.absolutelyrics.com/lyrics/view/the_beatles/lady_madonna", |
| 263 | + ), |
| 264 | + ( |
| 265 | + "Lady Madonna - The Beatles - LETRAS.MUS.BR", |
| 266 | + "https://www.letras.mus.br/the-beatles/275/", |
| 267 | + ), |
| 268 | + ( |
| 269 | + "The Beatles - Lady Madonna Lyrics", |
| 270 | + "https://www.lyricsmania.com/lady_madonna_lyrics_the_beatles.html", |
| 271 | + ), |
| 272 | + ( |
| 273 | + "Lady Madonna lyrics by The Beatles - original song full text. Official Lady Madonna lyrics, 2024 version | LyricsMode.com", # noqa: E501 |
| 274 | + "https://www.lyricsmode.com/lyrics/b/beatles/lady_madonna.html", |
| 275 | + ), |
| 276 | + ( |
| 277 | + "Paroles Lady Madonna par The Beatles - Lyrics - Paroles.net", |
| 278 | + "https://www.paroles.net/the-beatles/paroles-lady-madonna", |
| 279 | + ), |
| 280 | + ( |
| 281 | + "THE BEATLES - LADY MADONNA LYRICS", |
| 282 | + "https://www.songlyrics.com/the-beatles/lady-madonna-lyrics/", |
| 283 | + ), |
| 284 | + ( |
| 285 | + "The Beatles - Lady Madonna", |
| 286 | + "https://sweetslyrics.com/the-beatles/lady-madonna-lyrics", |
| 287 | + ), |
| 288 | + ( |
| 289 | + "Lady Madonna - Letra - The Beatles - Musica.com", |
| 290 | + "https://www.musica.com/letras.asp?letra=59862", |
| 291 | + ), |
| 292 | + ( |
| 293 | + "Paroles et traduction The Beatles : Lady Madonna - paroles de chanson", # noqa: E501 |
| 294 | + "https://www.lacoccinelle.net/259956-the-beatles-lady-madonna.html", |
| 295 | + ), |
244 | 296 | )
|
245 | 297 | ),
|
246 | 298 | pytest.param(
|
| 299 | + "The Beatles", |
247 | 300 | "Lady Madonna",
|
| 301 | + "The Beatles - Lady Madonna Lyrics | AZLyrics.com", |
248 | 302 | "https://www.azlyrics.com/lyrics/beatles/ladymadonna.html",
|
249 | 303 | marks=xfail_on_ci("AZLyrics is blocked by Cloudflare"),
|
250 | 304 | ),
|
251 | 305 | (
|
| 306 | + "Amy Winehouse", |
252 | 307 | "Jazz'n'blues",
|
253 |
| - "https://www.lyricsontop.com/amy-winehouse-songs/jazz-n-blues-lyrics.html", # noqa: E501 |
| 308 | + "Amy Winehouse - Jazz N' Blues lyrics complete", |
| 309 | + "https://www.lyricsontop.com/amy-winehouse-songs/jazz-n-blues-lyrics.html", |
254 | 310 | ),
|
255 | 311 | ],
|
256 | 312 | )
|
257 |
| - def test_backend_source(self, backend, title, url): |
| 313 | + def test_backend_source(self, fetch_lyrics, title): |
258 | 314 | """Test if lyrics present on websites registered in beets google custom
|
259 | 315 | search engine are correctly scraped.
|
260 | 316 | """
|
261 |
| - response = backend.fetch_url(url) |
262 |
| - result = lyrics.scrape_lyrics_from_html(response).lower() |
| 317 | + lyrics = fetch_lyrics() |
263 | 318 |
|
264 |
| - assert backend.is_lyrics(result) |
265 |
| - assert PHRASE_BY_TITLE[title] in result |
| 319 | + assert lyrics |
| 320 | + assert PHRASE_BY_TITLE[title].lower() in lyrics.lower() |
266 | 321 |
|
267 | 322 | def test_mocked_source_ok(self, backend, lyrics_html):
|
268 | 323 | """Test that lyrics of the mocked page are correctly scraped"""
|
|
0 commit comments