drop 3.8, add pytest-retry (#592)
* drop 3.8, add pytest-retry * fix mypy * fix missing import
This commit is contained in:
parent
08d9f3049c
commit
828b1b9810
26 changed files with 321 additions and 362 deletions
|
|
@ -3,7 +3,7 @@ import os
|
|||
import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
|
@ -17,7 +17,7 @@ from ytmusicapi.ytmusic import OAuthCredentials, YTMusic
|
|||
|
||||
|
||||
@pytest.fixture(name="blank_code")
|
||||
def fixture_blank_code() -> Dict[str, Any]:
|
||||
def fixture_blank_code() -> dict[str, Any]:
|
||||
return {
|
||||
"device_code": "",
|
||||
"user_code": "",
|
||||
|
|
@ -46,9 +46,11 @@ class TestOAuth:
|
|||
json_mock.side_effect = [blank_code, token_code]
|
||||
oauth_file = tempfile.NamedTemporaryFile(delete=False)
|
||||
oauth_filepath = oauth_file.name
|
||||
with mock.patch("builtins.input", return_value="y"), mock.patch(
|
||||
"sys.argv", ["ytmusicapi", "oauth", "--file", oauth_filepath]
|
||||
), mock.patch("webbrowser.open"):
|
||||
with (
|
||||
mock.patch("builtins.input", return_value="y"),
|
||||
mock.patch("sys.argv", ["ytmusicapi", "oauth", "--file", oauth_filepath]),
|
||||
mock.patch("webbrowser.open"),
|
||||
):
|
||||
main()
|
||||
assert Path(oauth_filepath).exists()
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import pytest
|
|||
|
||||
from ytmusicapi import YTMusic
|
||||
from ytmusicapi.constants import SUPPORTED_LANGUAGES
|
||||
from ytmusicapi.enums import ResponseStatus
|
||||
|
||||
|
||||
class TestPlaylists:
|
||||
|
|
@ -85,7 +86,7 @@ class TestPlaylists:
|
|||
playlist["tracks"][0]["setVideoId"],
|
||||
),
|
||||
)
|
||||
assert response1 == "STATUS_SUCCEEDED", "Playlist edit 1 failed"
|
||||
assert response1 == ResponseStatus.SUCCEEDED, "Playlist edit 1 failed"
|
||||
response2 = yt_brand.edit_playlist(
|
||||
playlist["id"],
|
||||
title=playlist["title"],
|
||||
|
|
@ -96,7 +97,7 @@ class TestPlaylists:
|
|||
playlist["tracks"][1]["setVideoId"],
|
||||
),
|
||||
)
|
||||
assert response2 == "STATUS_SUCCEEDED", "Playlist edit 2 failed"
|
||||
assert response2 == ResponseStatus.SUCCEEDED, "Playlist edit 2 failed"
|
||||
response3 = yt_brand.edit_playlist(
|
||||
playlist["id"],
|
||||
title=playlist["title"],
|
||||
|
|
@ -120,7 +121,7 @@ class TestPlaylists:
|
|||
source_playlist="OLAK5uy_nvjTE32aFYdFN7HCyMv3cGqD3wqBb4Jow",
|
||||
duplicates=True,
|
||||
)
|
||||
assert response["status"] == "STATUS_SUCCEEDED", "Adding playlist item failed"
|
||||
assert response["status"] == ResponseStatus.SUCCEEDED, "Adding playlist item failed"
|
||||
assert len(response["playlistEditResults"]) > 0, "Adding playlist item failed"
|
||||
time.sleep(3)
|
||||
yt_brand.edit_playlist(playlist_id, addToTop=False)
|
||||
|
|
@ -128,5 +129,5 @@ class TestPlaylists:
|
|||
playlist = yt_brand.get_playlist(playlist_id, related=True)
|
||||
assert len(playlist["tracks"]) == 46, "Getting playlist items failed"
|
||||
response = yt_brand.remove_playlist_items(playlist_id, playlist["tracks"])
|
||||
assert response == "STATUS_SUCCEEDED", "Playlist item removal failed"
|
||||
assert response == ResponseStatus.SUCCEEDED, "Playlist item removal failed"
|
||||
yt_brand.delete_playlist(playlist_id)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import time
|
|||
import pytest
|
||||
|
||||
from tests.conftest import get_resource
|
||||
from ytmusicapi.enums import ResponseStatus
|
||||
from ytmusicapi.ytmusic import YTMusic
|
||||
|
||||
|
||||
|
|
@ -38,8 +39,9 @@ class TestUploads:
|
|||
def test_upload_song_exceptions(self, config, yt_auth, yt_oauth):
|
||||
with pytest.raises(Exception, match="The provided file does not exist."):
|
||||
yt_auth.upload_song("song.wav")
|
||||
with tempfile.NamedTemporaryFile(suffix="wav") as temp, pytest.raises(
|
||||
Exception, match="The provided file type is not supported"
|
||||
with (
|
||||
tempfile.NamedTemporaryFile(suffix="wav") as temp,
|
||||
pytest.raises(Exception, match="The provided file type is not supported"),
|
||||
):
|
||||
yt_auth.upload_song(temp.name)
|
||||
with pytest.raises(Exception, match="Please provide browser authentication"):
|
||||
|
|
@ -59,14 +61,14 @@ class TestUploads:
|
|||
for song in songs:
|
||||
if song.get("title") in config["uploads"]["file"]:
|
||||
delete_response = yt_auth.delete_upload_entity(song["entityId"])
|
||||
assert delete_response == "STATUS_SUCCEEDED"
|
||||
assert delete_response == ResponseStatus.SUCCEEDED
|
||||
# Need to wait for song to be fully deleted
|
||||
time.sleep(10)
|
||||
# Now re-upload
|
||||
upload_response = yt_auth.upload_song(get_resource(config["uploads"]["file"]))
|
||||
|
||||
assert (
|
||||
upload_response == "STATUS_SUCCEEDED" or upload_response.status_code == 200
|
||||
upload_response == ResponseStatus.SUCCEEDED or upload_response.status_code == 200
|
||||
), f"Song failed to upload {upload_response}"
|
||||
|
||||
# Wait for upload to finish processing and verify it can be retrieved
|
||||
|
|
@ -86,7 +88,7 @@ class TestUploads:
|
|||
def test_delete_upload_entity(self, yt_oauth):
|
||||
results = yt_oauth.get_library_upload_songs()
|
||||
response = yt_oauth.delete_upload_entity(results[0]["entityId"])
|
||||
assert response == "STATUS_SUCCEEDED"
|
||||
assert response == ResponseStatus.SUCCEEDED
|
||||
|
||||
def test_get_library_upload_album(self, config, yt_oauth):
|
||||
album = yt_oauth.get_library_upload_album(config["uploads"]["private_album_id"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue