Skip to content

Commit

Permalink
test(cli): Update remove_library test to try to remove a single song …
Browse files Browse the repository at this point in the history
…from the library
  • Loading branch information
apastel committed Feb 23, 2025
1 parent b63c605 commit 7f104d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def fixture_sample_album() -> str:

@pytest.fixture(name="sample_album_as_playlist")
def fixture_sample_album_as_playlist() -> str:
"""Eminem - Revival"""
return "OLAK5uy_nMr9h2VlS-2PULNz3M3XVXQj_P3C2bqaY"
"""Metallica - Metallica (The Black Album)"""
return "OLAK5uy_mcL5K5E9IHM5GPQ-8AyzPM7JgQMMn1uhs"


@pytest.fixture(name="sample_video")
Expand Down Expand Up @@ -319,14 +319,36 @@ def fixture_add_library_album(yt_browser: YTMusic, sample_album_as_playlist):
while retries_remaining:
albums = yt_browser.get_library_albums(limit=None)
for album in albums:
if album.get("title") == "Revival":
if album.get("title") == "Metallica":
return album
retries_remaining -= 1
time.sleep(2)

raise AssertionError("Failed to confirm that album was added to library")


@pytest.fixture(name="add_library_song")
def fixture_add_library_song(yt_browser: YTMusic, sample_album):
catalog_album = yt_browser.get_album(sample_album)
add_token = catalog_album.get("tracks")[0]["feedbackTokens"]["add"]
print(add_token)
response = yt_browser.edit_song_library_status([add_token])
print(response)
assert "actions" in response

# Wait for song to finish processing
retries_remaining = 5
while retries_remaining:
songs = yt_browser.get_library_songs(limit=None)
for song in songs:
if song.get("title") == "Walk On Water (feat. Beyoncé)":
return song
retries_remaining -= 1
time.sleep(2)

raise AssertionError("Failed to confirm that song was added to library")


@pytest.fixture(name="add_podcast")
def fixture_add_podcast(yt_browser: YTMusic, sample_podcast):
response = yt_browser.rate_playlist(sample_podcast, const.LIKE)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def verify_added_to_library(self, yt_browser: YTMusic, config, result):
return True
raise AssertionError("Uploaded song was not added to library before deleting")

def test_remove_library(self, yt_browser: YTMusic, add_library_album, add_podcast):
def test_remove_library(self, yt_browser: YTMusic, add_library_album, add_podcast, add_library_song):
runner = CliRunner()
result = runner.invoke(cli, ["remove-library"], standalone_mode=False, obj=yt_browser)
print(result.stdout)
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_add_all_library_songs_to_playlist(
)
print(result.stdout)
time.sleep(3)
assert 30 <= len(yt_browser.get_playlist(get_playlist_with_dupes).get("tracks"))
assert len(yt_browser.get_playlist(get_playlist_with_dupes).get("tracks")) >= 25
assert result.exit_code == 0

def test_add_all_uploaded_songs_to_playlist(self, yt_browser: YTMusic, get_playlist_with_dupes: str, upload_song):
Expand Down

0 comments on commit 7f104d2

Please sign in to comment.