Skip to content

Commit d7055fa

Browse files
author
Paldin Bet Eivaz
committed
added test for track_for_id method
1 parent 281eec8 commit d7055fa

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/test_spotify.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,67 @@ def test_track_request(self):
127127
self.assertIn('album:Despicable Me 2', query)
128128
self.assertEqual(params['type'], ['track'])
129129

130+
@responses.activate
131+
def test_track_for_id(self):
132+
"""Tests if plugin is able to fetch a track by its Spotify ID"""
133+
134+
# Mock the Spotify 'Get Track' call
135+
json_file = os.path.join(
136+
_common.RSRC, b'spotify', b'track_info.json'
137+
)
138+
with open(json_file, 'rb') as f:
139+
response_body = f.read()
140+
141+
responses.add(
142+
responses.GET,
143+
spotify.SpotifyPlugin.track_url + '6NPVjNh8Jhru9xOmyQigds',
144+
body=response_body,
145+
status=200,
146+
content_type='application/json',
147+
)
148+
149+
# Mock the Spotify 'Get Album' call
150+
json_file = os.path.join(
151+
_common.RSRC, b'spotify', b'album_info.json'
152+
)
153+
with open(json_file, 'rb') as f:
154+
response_body = f.read()
155+
156+
responses.add(
157+
responses.GET,
158+
spotify.SpotifyPlugin.album_url + '5l3zEmMrOhOzG8d8s83GOL',
159+
body=response_body,
160+
status=200,
161+
content_type='application/json',
162+
)
163+
164+
# Mock the Spotify 'Search' call
165+
json_file = os.path.join(
166+
_common.RSRC, b'spotify', b'track_request.json'
167+
)
168+
with open(json_file, 'rb') as f:
169+
response_body = f.read()
170+
171+
responses.add(
172+
responses.GET,
173+
spotify.SpotifyPlugin.search_url,
174+
body=response_body,
175+
status=200,
176+
content_type='application/json',
177+
)
178+
179+
track_info = self.spotify.track_for_id('6NPVjNh8Jhru9xOmyQigds')
180+
item = Item(
181+
mb_trackid=track_info.track_id,
182+
albumartist=track_info.artist,
183+
title=track_info.title,
184+
length=track_info.length
185+
)
186+
item.add(self.lib)
187+
188+
results = self.spotify._match_library_tracks(self.lib, "Happy")
189+
self.assertEqual(1, len(results))
190+
self.assertEqual("6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
130191

131192
def suite():
132193
return unittest.TestLoader().loadTestsFromName(__name__)

0 commit comments

Comments
 (0)