Skip to content

Commit

Permalink
Merge pull request #131 from kingosticks/fix/search-tracks-available
Browse files Browse the repository at this point in the history
Fix missing / unavailable tracks in search results
  • Loading branch information
jodal authored Jun 11, 2017
2 parents af6994d + 8eb583e commit 4e9b82c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions mopidy_spotify/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def search(config, session, web_client,
result = web_client.get(_API_BASE_URI, params={
'q': sp_query,
'limit': search_count,
'market': session.user_country,
'type': ','.join(types)})

albums = [
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def session_mock():
sp_session_mock = mock.Mock(spec=spotify.Session)
sp_session_mock.connection.state = spotify.ConnectionState.LOGGED_IN
sp_session_mock.playlist_container = []
sp_session_mock.user_country = 'GB'
return sp_session_mock


Expand Down
21 changes: 21 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_search_returns_albums_and_artists_and_tracks(
params={
'q': '"ABBA"',
'limit': 50,
'market': 'GB',
'type': 'album,artist,track'})

assert 'Searching Spotify for: "ABBA"' in caplog.text()
Expand Down Expand Up @@ -124,6 +125,7 @@ def test_sets_api_limit_to_album_count_when_max(
params={
'q': '"ABBA"',
'limit': 6,
'market': 'GB',
'type': 'album,artist,track'})

assert len(result.albums) == 6
Expand All @@ -144,6 +146,7 @@ def test_sets_api_limit_to_artist_count_when_max(
params={
'q': '"ABBA"',
'limit': 6,
'market': 'GB',
'type': 'album,artist,track'})

assert len(result.artists) == 6
Expand All @@ -164,6 +167,7 @@ def test_sets_api_limit_to_track_count_when_max(
params={
'q': '"ABBA"',
'limit': 6,
'market': 'GB',
'type': 'album,artist,track'})

assert len(result.tracks) == 6
Expand All @@ -183,9 +187,26 @@ def test_sets_types_parameter(
params={
'q': '"ABBA"',
'limit': 50,
'market': 'GB',
'type': 'album,artist'})


def test_sets_market_parameter_from_user_country(
web_client_mock, web_search_mock_large, provider, session_mock):
session_mock.user_country = 'SE'
web_client_mock.get.return_value = web_search_mock_large

provider.search({'any': ['ABBA']})

web_client_mock.get.assert_called_once_with(
'https://api.spotify.com/v1/search',
params={
'q': '"ABBA"',
'limit': 50,
'market': 'SE',
'type': 'album,artist,track'})


def test_handles_empty_response(web_client_mock, provider):
web_client_mock.get.return_value = {}

Expand Down

0 comments on commit 4e9b82c

Please sign in to comment.