Skip to content

Commit

Permalink
Merge pull request #399 from kingosticks/ruffage
Browse files Browse the repository at this point in the history
Fix fuff complaints
  • Loading branch information
kingosticks authored Sep 25, 2024
2 parents e088c33 + 1a3d22a commit 2101b7f
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/mopidy_spotify/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class ExpiryStrategy(StrEnum):


class WebResponse(dict):
def __init__( # noqa: PLR0913
def __init__(
self,
url,
data,
Expand Down
49 changes: 25 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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]},
Expand All @@ -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},
Expand All @@ -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],
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -125,25 +126,25 @@ 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,
"album": 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",
Expand All @@ -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",
Expand All @@ -169,7 +170,7 @@ def web_oauth_mock():
}


@pytest.fixture()
@pytest.fixture
def web_playlist_mock(web_track_mock):
return {
"owner": {"id": "alice"},
Expand All @@ -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],
Expand All @@ -196,15 +197,15 @@ 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"
web_client_mock.get_user_playlists.return_value = []
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
Expand All @@ -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
Expand All @@ -222,6 +223,6 @@ def backend_listener_mock():
patcher.stop()


@pytest.fixture()
@pytest.fixture
def provider(backend_mock):
return library.SpotifyLibraryProvider(backend_mock)
2 changes: 1 addition & 1 deletion tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
1 change: 1 addition & 0 deletions tests/test_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from mopidy import models

from mopidy_spotify.browse import BROWSE_DIR_URIS


Expand Down
5 changes: 3 additions & 2 deletions tests/test_distinct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_images.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import mopidy
import pytest

from mopidy_spotify import lookup


Expand Down
7 changes: 4 additions & 3 deletions tests/test_playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import mock

from mopidy import models

from mopidy_spotify import lookup, search, translator


Expand Down
1 change: 1 addition & 0 deletions tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from mopidy import models

from mopidy_spotify import translator


Expand Down
Loading

0 comments on commit 2101b7f

Please sign in to comment.