Files
lintunes/tests/test_round58.py
T
travandClaude Opus 5 ec008fc1e9 v0.22.0: lookup on youtube
Right-click a song -> "lookup on youtube" opens a YouTube search for
"<title> <artist>" in the default browser. Single selection only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 23:06:38 -07:00

39 lines
1.2 KiB
Python

"""Round 58: "lookup on youtube" in a song's right-click menu.
The URL is built by a pure helper so the query encoding can be checked
without opening a browser.
"""
from PyQt6.QtCore import QUrl, QUrlQuery
from lintunes.models import Track
from lintunes.gui.track_table import youtube_search_url
def _query(url):
return QUrlQuery(url).queryItemValue(
"search_query", QUrl.ComponentFormattingOption.FullyDecoded)
def test_title_then_artist(qapp):
url = youtube_search_url(Track(track_id=1, name="I Know", artist="Dionne Farris"))
assert url.scheme() == "https"
assert url.host() == "www.youtube.com"
assert url.path() == "/results"
assert _query(url) == "I Know Dionne Farris"
def test_special_characters_survive(qapp):
track = Track(track_id=1, name="Rock & Roll #9 ✨", artist="Beyoncé")
url = youtube_search_url(track)
assert _query(url) == "Rock & Roll #9 ✨ Beyoncé"
encoded = url.toString(QUrl.ComponentFormattingOption.FullyEncoded)
assert "&" not in encoded.split("search_query=", 1)[1]
assert "#" not in encoded
def test_missing_artist_has_no_trailing_space(qapp):
url = youtube_search_url(Track(track_id=1, name="Zuuso"))
assert _query(url) == "Zuuso"