Fix genius end to end lyrics test

This commit is contained in:
Šarūnas Nejus 2026-02-25 21:07:26 +00:00
parent c239275193
commit 835115a6f7
No known key found for this signature in database
3 changed files with 33 additions and 13 deletions

View file

@ -85,6 +85,15 @@ class GeniusAPI:
class Search(TypedDict):
response: GeniusAPI.SearchResponse
class StatusResponse(TypedDict):
status: int
message: str
class Meta(TypedDict):
meta: GeniusAPI.StatusResponse
Response = Search | Meta
class GoogleCustomSearchAPI:
class Response(TypedDict):

View file

@ -67,6 +67,10 @@ class CaptchaError(requests.exceptions.HTTPError):
super().__init__("Captcha is required", *args, **kwargs)
class GeniusHTTPError(requests.exceptions.HTTPError):
pass
# Utilities.
@ -564,8 +568,16 @@ class Genius(SearchBackend):
def headers(self) -> dict[str, str]:
return {"Authorization": f"Bearer {self.config['genius_api_key']}"}
def get_json(self, *args, **kwargs) -> GeniusAPI.Search:
response: GeniusAPI.Response = super().get_json(*args, **kwargs)
if "response" in response:
return response # type: ignore[return-value]
meta = response["meta"]
raise GeniusHTTPError(f"{meta['message']} Status: {meta['status']}")
def search(self, artist: str, title: str) -> Iterable[SearchResult]:
search_data: GeniusAPI.Search = self.get_json(
search_data = self.get_json(
self.SEARCH_URL,
params={"q": f"{artist} {title}"},
headers=self.headers,

View file

@ -133,15 +133,13 @@ lyrics_pages = [
LyricsPage.make(
"https://genius.com/The-beatles-lady-madonna-lyrics",
"""
[Intro: Instrumental]
[Verse 1: Paul McCartney]
Lady Madonna, children at your feet
Wonder how you manage to make ends meet
Who finds the money when you pay the rent?
Did you think that money was heaven sent?
[Bridge: Paul McCartney]
[Bridge: Paul McCartney, Paul McCartney, John Lennon & George Harrison]
Friday night arrives without a suitcase
Sunday morning creeping like a nun
Monday's child has learned to tie his bootlace
@ -150,27 +148,28 @@ lyrics_pages = [
[Verse 2: Paul McCartney]
Lady Madonna, baby at your breast
Wonders how you manage to feed the rest
[Bridge: Paul McCartney, John Lennon & George Harrison]
[Tenor Saxophone Solo: Ronnie Scott]
[Bridge: John Lennon & George Harrison, Paul McCartney, John Lennon & George Harrison]
Pa-pa-pa-pa, pa-pa-pa-pa-pa
Pa-pa-pa-pa-pa, pa-pa-pa, pa-pa, pa-pa
Pa-pa-pa-pa, pa-pa-pa-pa-pa
See how they run
[Verse 3: Paul McCartney]
Lady Madonna, lying on the bed
Listen to the music playing in your head
[Bridge: Paul McCartney]
Tuesday afternoon is never ending
Wednesday morning papers didn't come
Thursday night your stockings needed mending
[Bridge: Paul McCartney, John Lennon & George Harrison, Paul McCartney, John Lennon & George Harrison]
Tuesday afternoon is never ending (Pa-pa-pa-pa, pa-pa-pa-pa-pa)
Wednesday morning, papers didn't come (Pa-pa-pa-pa-pa, pa-pa-pa, pa-pa, pa-pa)
Thursday night, your stockings needed mending (Pa-pa-pa-pa, pa-pa-pa-pa-pa)
See how they run
[Verse 4: Paul McCartney]
Lady Madonna, children at your feet
Wonder how you manage to make ends meet
[Outro: Instrumental]
""",
""", # noqa: E501
marks=[xfail_on_ci("Genius returns 403 FORBIDDEN in CI")],
),
LyricsPage.make(