diff --git a/src/mopidy_spotify/web.py b/src/mopidy_spotify/web.py index d51888f4..e84e207b 100644 --- a/src/mopidy_spotify/web.py +++ b/src/mopidy_spotify/web.py @@ -277,7 +277,7 @@ class ExpiryStrategy(StrEnum): class WebResponse(dict): - def __init__( # noqa: PLR0913 + def __init__( self, url, data, diff --git a/tests/conftest.py b/tests/conftest.py index a7708868..7f7ae36e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,16 +3,17 @@ import pytest from mopidy import backend as backend_api from mopidy import models + from mopidy_spotify import backend, library, utils, web -@pytest.fixture() +@pytest.fixture def caplog(caplog): caplog.set_level(utils.TRACE) return caplog -@pytest.fixture() +@pytest.fixture def config(tmp_path): return { "core": { @@ -38,14 +39,14 @@ def config(tmp_path): } -@pytest.fixture() +@pytest.fixture def web_mock(): patcher = mock.patch.object(backend, "web", spec=web) yield patcher.start() patcher.stop() -@pytest.fixture() +@pytest.fixture def web_search_mock(web_album_mock_base, web_artist_mock, web_track_mock): return { "albums": {"items": [web_album_mock_base]}, @@ -54,7 +55,7 @@ def web_search_mock(web_album_mock_base, web_artist_mock, web_track_mock): } -@pytest.fixture() +@pytest.fixture def web_search_mock_large(web_album_mock, web_artist_mock, web_track_mock): return { "albums": {"items": [web_album_mock] * 10}, @@ -63,12 +64,12 @@ def web_search_mock_large(web_album_mock, web_artist_mock, web_track_mock): } -@pytest.fixture() +@pytest.fixture def web_artist_mock(): return {"name": "ABBA", "uri": "spotify:artist:abba", "type": "artist"} -@pytest.fixture() +@pytest.fixture def web_track_mock_base(web_artist_mock): return { "artists": [web_artist_mock], @@ -83,7 +84,7 @@ def web_track_mock_base(web_artist_mock): } -@pytest.fixture() +@pytest.fixture def web_album_mock_base(web_artist_mock): return { "name": "DEF 456", @@ -95,7 +96,7 @@ def web_album_mock_base(web_artist_mock): } -@pytest.fixture() +@pytest.fixture def web_album_mock(web_album_mock_base, web_track_mock_base): return { **web_album_mock_base, @@ -104,7 +105,7 @@ def web_album_mock(web_album_mock_base, web_track_mock_base): } -@pytest.fixture() +@pytest.fixture def web_album_mock_base2(web_artist_mock): return { "name": "XYZ 789", @@ -116,7 +117,7 @@ def web_album_mock_base2(web_artist_mock): } -@pytest.fixture() +@pytest.fixture def web_album_mock2(web_album_mock_base2, web_track_mock_base): return { **web_album_mock_base2, @@ -125,7 +126,7 @@ def web_album_mock2(web_album_mock_base2, web_track_mock_base): } -@pytest.fixture() +@pytest.fixture def web_track_mock(web_track_mock_base, web_album_mock_base): return { **web_track_mock_base, @@ -133,17 +134,17 @@ def web_track_mock(web_track_mock_base, web_album_mock_base): } -@pytest.fixture() +@pytest.fixture def web_track_mock_link(web_track_mock): return web.WebLink.from_uri(web_track_mock["uri"]) -@pytest.fixture() +@pytest.fixture def web_album_mock_link(web_album_mock): return web.WebLink.from_uri(web_album_mock["uri"]) -@pytest.fixture() +@pytest.fixture def web_response_mock(web_track_mock): return web.WebResponse( "https://api.spotify.com/v1/tracks/abc", @@ -153,13 +154,13 @@ def web_response_mock(web_track_mock): ) -@pytest.fixture() +@pytest.fixture def web_response_mock_etag(web_response_mock): web_response_mock._etag = '"1234"' return web_response_mock -@pytest.fixture() +@pytest.fixture def web_oauth_mock(): return { "access_token": "NgCXRK...MzYjw", @@ -169,7 +170,7 @@ def web_oauth_mock(): } -@pytest.fixture() +@pytest.fixture def web_playlist_mock(web_track_mock): return { "owner": {"id": "alice"}, @@ -181,12 +182,12 @@ def web_playlist_mock(web_track_mock): } -@pytest.fixture() +@pytest.fixture def mopidy_artist_mock(): return models.Artist(name="ABBA", uri="spotify:artist:abba") -@pytest.fixture() +@pytest.fixture def mopidy_album_mock(mopidy_artist_mock): return models.Album( artists=[mopidy_artist_mock], @@ -196,7 +197,7 @@ def mopidy_album_mock(mopidy_artist_mock): ) -@pytest.fixture() +@pytest.fixture def web_client_mock(): web_client_mock = mock.MagicMock(spec=web.SpotifyOAuthClient) web_client_mock.user_id = "alice" @@ -204,7 +205,7 @@ def web_client_mock(): return web_client_mock -@pytest.fixture() +@pytest.fixture def backend_mock(config, web_client_mock): backend_mock = mock.Mock(spec=backend.SpotifyBackend) backend_mock._config = config @@ -213,7 +214,7 @@ def backend_mock(config, web_client_mock): return backend_mock -@pytest.fixture() +@pytest.fixture def backend_listener_mock(): patcher = mock.patch.object( backend_api, "BackendListener", spec=backend_api.BackendListener @@ -222,6 +223,6 @@ def backend_listener_mock(): patcher.stop() -@pytest.fixture() +@pytest.fixture def provider(backend_mock): return library.SpotifyLibraryProvider(backend_mock) diff --git a/tests/test_backend.py b/tests/test_backend.py index e0321e41..f924a126 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -1,9 +1,9 @@ from unittest import mock, skip from mopidy import backend as backend_api + from mopidy_spotify import backend, library, playlists from mopidy_spotify.backend import SpotifyPlaybackProvider - from tests import ThreadJoiner diff --git a/tests/test_browse.py b/tests/test_browse.py index 6af4165a..65e3b21c 100644 --- a/tests/test_browse.py +++ b/tests/test_browse.py @@ -2,6 +2,7 @@ import pytest from mopidy import models + from mopidy_spotify.browse import BROWSE_DIR_URIS diff --git a/tests/test_distinct.py b/tests/test_distinct.py index 4501e0e4..5b866004 100644 --- a/tests/test_distinct.py +++ b/tests/test_distinct.py @@ -2,10 +2,11 @@ import pytest from mopidy import models + from mopidy_spotify import distinct, playlists, search -@pytest.fixture() +@pytest.fixture def web_client_mock_with_playlists( web_client_mock, web_playlist_mock, @@ -19,7 +20,7 @@ def web_client_mock_with_playlists( return web_client_mock -@pytest.fixture() +@pytest.fixture def search_mock(mopidy_album_mock, mopidy_artist_mock): patcher = mock.patch.object(distinct, "search", spec=search) search_mock = patcher.start() diff --git a/tests/test_images.py b/tests/test_images.py index 93921116..c1e770a4 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -1,10 +1,11 @@ import pytest from mopidy import models + from mopidy_spotify import images from mopidy_spotify.web import LinkType, WebLink -@pytest.fixture() +@pytest.fixture def img_provider(provider): images._cache = {} return provider diff --git a/tests/test_lookup.py b/tests/test_lookup.py index 24f8731a..2af1748f 100644 --- a/tests/test_lookup.py +++ b/tests/test_lookup.py @@ -3,6 +3,7 @@ import mopidy import pytest + from mopidy_spotify import lookup diff --git a/tests/test_playback.py b/tests/test_playback.py index 575e74e0..f32617ca 100644 --- a/tests/test_playback.py +++ b/tests/test_playback.py @@ -3,22 +3,23 @@ import pytest from mopidy import audio from mopidy import backend as backend_api + from mopidy_spotify import backend -@pytest.fixture() +@pytest.fixture def audio_mock(): return mock.Mock(spec=audio.Audio) -@pytest.fixture() +@pytest.fixture def backend_mock(config): backend_mock = mock.Mock(spec=backend.SpotifyBackend) backend_mock._config = config return backend_mock -@pytest.fixture() +@pytest.fixture def provider(audio_mock, backend_mock): return backend.SpotifyPlaybackProvider(audio=audio_mock, backend=backend_mock) diff --git a/tests/test_playlists.py b/tests/test_playlists.py index 11afd383..b2e7d68b 100644 --- a/tests/test_playlists.py +++ b/tests/test_playlists.py @@ -4,12 +4,12 @@ import pytest from mopidy import backend as backend_api from mopidy.models import Ref -from mopidy_spotify import playlists +from mopidy_spotify import playlists from tests import ThreadJoiner -@pytest.fixture() +@pytest.fixture def web_client_mock(web_client_mock, web_track_mock): web_playlist1 = { "owner": {"id": "alice"}, @@ -42,7 +42,7 @@ def get_playlist(*args, **kwargs): return web_client_mock -@pytest.fixture() +@pytest.fixture def provider(backend_mock, web_client_mock): backend_mock._web_client = web_client_mock return playlists.SpotifyPlaylistsProvider(backend_mock) diff --git a/tests/test_search.py b/tests/test_search.py index a30d2b13..3ed9abe8 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,6 +1,7 @@ from unittest import mock from mopidy import models + from mopidy_spotify import lookup, search, translator diff --git a/tests/test_translator.py b/tests/test_translator.py index 7724c578..0b1a2abe 100644 --- a/tests/test_translator.py +++ b/tests/test_translator.py @@ -3,6 +3,7 @@ import pytest from mopidy import models + from mopidy_spotify import translator diff --git a/tests/test_web.py b/tests/test_web.py index 1dba2cad..47c3bcd7 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -2,15 +2,16 @@ from datetime import UTC, datetime from unittest import mock -import mopidy_spotify import pytest import requests import responses -from mopidy_spotify import web from responses import matchers +import mopidy_spotify +from mopidy_spotify import web + -@pytest.fixture() +@pytest.fixture def oauth_client(config): return web.OAuthClient( base_url="https://api.spotify.com/v1", @@ -22,7 +23,7 @@ def oauth_client(config): ) -@pytest.fixture() +@pytest.fixture def mock_time(): patcher = mock.patch.object(web.time, "time") mock_time = patcher.start() @@ -30,7 +31,7 @@ def mock_time(): patcher.stop() -@pytest.fixture() +@pytest.fixture def mock_now(): patcher = mock.patch("mopidy_spotify.web.datetime") mock_datetime = patcher.start() @@ -40,7 +41,7 @@ def mock_now(): patcher.stop() -@pytest.fixture() +@pytest.fixture def skip_refresh_token(): patcher = mock.patch.object( web.OAuthClient, "_should_refresh_token", return_value=False @@ -715,7 +716,7 @@ def test_updated_responses_changed(web_response_mock, oauth_client, mock_time): assert not result.status_unchanged -@pytest.fixture() +@pytest.fixture def spotify_client(config): client = web.SpotifyOAuthClient( client_id=config["spotify"]["client_id"], @@ -747,7 +748,7 @@ def playlist_tracks_parms(): ) -@pytest.fixture() +@pytest.fixture def bar_playlist(playlist_parms): return { "href": url(f"playlists/bar?{playlist_parms}"), @@ -755,7 +756,7 @@ def bar_playlist(playlist_parms): } -@pytest.fixture() +@pytest.fixture def foo_playlist_tracks(playlist_tracks_parms): return { "href": url(f"playlists/foo/tracks?{playlist_tracks_parms}"), @@ -763,7 +764,7 @@ def foo_playlist_tracks(playlist_tracks_parms): } -@pytest.fixture() +@pytest.fixture def foo_playlist(playlist_parms, foo_playlist_tracks): return { "href": url(f"playlists/foo?{playlist_parms}"), @@ -771,7 +772,7 @@ def foo_playlist(playlist_parms, foo_playlist_tracks): } -@pytest.fixture() +@pytest.fixture def foo_album_next_tracks(): params = urllib.parse.urlencode({"market": "from_token", "offset": 3}) return { @@ -781,7 +782,7 @@ def foo_album_next_tracks(): } -@pytest.fixture() +@pytest.fixture def foo_album(foo_album_next_tracks): params = urllib.parse.urlencode({"market": "from_token"}) return { @@ -795,12 +796,12 @@ def foo_album(foo_album_next_tracks): } -@pytest.fixture() +@pytest.fixture def foo_album_response(foo_album): return web.WebResponse(foo_album["href"], foo_album) -@pytest.fixture() +@pytest.fixture def artist_albums_mock(web_album_mock_base, web_album_mock_base2): params = urllib.parse.urlencode( {"market": "from_token", "include_groups": "single,album"}