mirror of
https://github.com/beetbox/beets.git
synced 2026-01-09 09:22:55 +01:00
appease Flake8
This commit is contained in:
parent
dc77943da2
commit
337cf2a1c3
2 changed files with 17 additions and 14 deletions
|
|
@ -16,7 +16,7 @@ from beets.autotag.hooks import AlbumInfo, TrackInfo
|
|||
|
||||
|
||||
class SpotifyPlugin(BeetsPlugin):
|
||||
# URL for the Web API of Spotify
|
||||
# Endpoints for the Spotify API
|
||||
# Documentation here: https://developer.spotify.com/web-api/search-item/
|
||||
oauth_token_url = 'https://accounts.spotify.com/api/token'
|
||||
base_url = 'https://api.spotify.com/v1/search'
|
||||
|
|
@ -54,7 +54,9 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
self.setup()
|
||||
|
||||
def setup(self):
|
||||
"""Retrieve previously saved OAuth token or generate a new one"""
|
||||
"""
|
||||
Retrieve previously saved OAuth token or generate a new one
|
||||
"""
|
||||
try:
|
||||
with open(self.tokenfile) as f:
|
||||
token_data = json.load(f)
|
||||
|
|
@ -113,8 +115,8 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
|
||||
def album_for_id(self, album_id):
|
||||
"""
|
||||
Fetches an album by its Spotify album ID or URL and returns an AlbumInfo object
|
||||
or None if the album is not found.
|
||||
Fetches an album by its Spotify album ID or URL and returns an
|
||||
AlbumInfo object or None if the album is not found.
|
||||
"""
|
||||
self._log.debug(u'Searching for album {}', album_id)
|
||||
match = re.search(self.id_regex.format('album'), album_id)
|
||||
|
|
@ -180,8 +182,8 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
|
||||
def track_for_id(self, track_id):
|
||||
"""
|
||||
Fetches a track by its Spotify track ID or URL and returns a TrackInfo object
|
||||
or None if the track is not found.
|
||||
Fetches a track by its Spotify track ID or URL and returns a
|
||||
TrackInfo object or None if the track is not found.
|
||||
"""
|
||||
self._log.debug(u'Searching for track {}', track_id)
|
||||
match = re.search(self.id_regex.format('track'), track_id)
|
||||
|
|
|
|||
|
|
@ -38,27 +38,28 @@ class SpotifyPluginTest(_common.TestCase, TestHelper):
|
|||
spotify.SpotifyPlugin.oauth_token_url,
|
||||
status=200,
|
||||
json={
|
||||
'access_token': '3XyiC3raJySbIAV5LVYj1DaWbcocNi3LAJTNXRnYYGVUl6mbbqXNhW3YcZnQgYXNWHFkVGSMlc0tMuvq8CF',
|
||||
'access_token': '3XyiC3raJySbIAV5LVYj1DaWbcocNi3LAJTNXRnYY'
|
||||
'GVUl6mbbqXNhW3YcZnQgYXNWHFkVGSMlc0tMuvq8CF',
|
||||
'token_type': 'Bearer',
|
||||
'expires_in': 3600,
|
||||
'scope': '',
|
||||
},
|
||||
)
|
||||
self.spotify = spotify.SpotifyPlugin()
|
||||
opts = ArgumentsMock("list", False)
|
||||
opts = ArgumentsMock('list', False)
|
||||
self.spotify.parse_opts(opts)
|
||||
|
||||
def tearDown(self):
|
||||
self.teardown_beets()
|
||||
|
||||
def test_args(self):
|
||||
opts = ArgumentsMock("fail", True)
|
||||
opts = ArgumentsMock('fail', True)
|
||||
self.assertEqual(False, self.spotify.parse_opts(opts))
|
||||
opts = ArgumentsMock("list", False)
|
||||
opts = ArgumentsMock('list', False)
|
||||
self.assertEqual(True, self.spotify.parse_opts(opts))
|
||||
|
||||
def test_empty_query(self):
|
||||
self.assertEqual(None, self.spotify.query_spotify(self.lib, u"1=2"))
|
||||
self.assertEqual(None, self.spotify.query_spotify(self.lib, u'1=2'))
|
||||
|
||||
@responses.activate
|
||||
def test_missing_request(self):
|
||||
|
|
@ -102,7 +103,7 @@ class SpotifyPluginTest(_common.TestCase, TestHelper):
|
|||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api.spotify.com/v1/search',
|
||||
spotify.SpotifyPlugin.base_url,
|
||||
body=response_body,
|
||||
status=200,
|
||||
content_type='application/json',
|
||||
|
|
@ -115,9 +116,9 @@ class SpotifyPluginTest(_common.TestCase, TestHelper):
|
|||
length=10,
|
||||
)
|
||||
item.add(self.lib)
|
||||
results = self.spotify.query_spotify(self.lib, u"Happy")
|
||||
results = self.spotify.query_spotify(self.lib, u'Happy')
|
||||
self.assertEqual(1, len(results))
|
||||
self.assertEqual(u"6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
|
||||
self.assertEqual(u'6NPVjNh8Jhru9xOmyQigds', results[0]['id'])
|
||||
self.spotify.output_results(results)
|
||||
|
||||
params = _params(responses.calls[0].request.url)
|
||||
|
|
|
|||
Loading…
Reference in a new issue