Fix audiobook integration tests (#1141)

This commit is contained in:
Stéphane Bruckert 2024-06-23 22:13:44 +01:00 committed by GitHub
parent c7856d0120
commit c90ce4a875
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 21 deletions

View File

@ -16,7 +16,7 @@ Add your changes below.
- Added test_artist_id, test_artist_url, and test_artists_mixed_ids to non_user_endpoints test.py - Added test_artist_id, test_artist_url, and test_artists_mixed_ids to non_user_endpoints test.py
### Fixed ### Fixed
- - Audiobook integration tests
### Removed ### Removed
- `mock` no longer listed as a test dependency. Only built-in `unittest.mock` is actually used. - `mock` no longer listed as a test dependency. Only built-in `unittest.mock` is actually used.

View File

@ -60,15 +60,12 @@ class AuthTestSpotipy(unittest.TestCase):
heavyweight_ep1_url = 'https://open.spotify.com/episode/68kq3bNz6hEuq8NtdfwERG' heavyweight_ep1_url = 'https://open.spotify.com/episode/68kq3bNz6hEuq8NtdfwERG'
reply_all_ep1_urn = 'spotify:episode:1KHjbpnmNpFmNTczQmTZlR' reply_all_ep1_urn = 'spotify:episode:1KHjbpnmNpFmNTczQmTZlR'
american_gods_urn = 'spotify:audiobook:1IcM9Untg6d3ktuwObYGcN' dune_urn = 'spotify:audiobook:7iHfbu1YPACw6oZPAFJtqe'
american_gods_id = '1IcM9Untg6d3ktuwObYGcN' dune_id = '7iHfbu1YPACw6oZPAFJtqe'
american_gods_url = 'https://open.spotify.com/audiobook/1IcM9Untg6d3ktuwObYGcN' dune_url = 'https://open.spotify.com/audiobook/7iHfbu1YPACw6oZPAFJtqe'
two_books = [
four_books = [ 'spotify:audiobook:7iHfbu1YPACw6oZPAFJtqe',
'spotify:audiobook:1IcM9Untg6d3ktuwObYGcN', 'spotify:audiobook:67VtmjZitn25TWocsyAEyh']
'spotify:audiobook:37sRC6carIX2Vf3Vv716T7',
'spotify:audiobook:1Gep4UJ95xQawA55OgRI8n',
'spotify:audiobook:4Sm381mcf5gBsi9yfhqgVB']
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
@ -337,7 +334,7 @@ class AuthTestSpotipy(unittest.TestCase):
def find_album(): def find_album():
for album in results['items']: for album in results['items']:
if album['name'] == 'Death to False Metal': if 'Weezer' in album['name']: # Weezer has many albums containing Weezer
return True return True
return False return False
@ -485,27 +482,25 @@ class AuthTestSpotipy(unittest.TestCase):
self.assertIn("GB", markets) self.assertIn("GB", markets)
def test_get_audiobook(self): def test_get_audiobook(self):
audiobook = self.spotify.get_audiobook(self.american_gods_urn, market="US") audiobook = self.spotify.get_audiobook(self.dune_urn, market="US")
self.assertTrue(audiobook['name'] == self.assertTrue(audiobook['name'] ==
'American Gods: The Tenth Anniversary Edition: A Novel') 'Dune: Book One in the Dune Chronicles')
def test_get_audiobook_bad_urn(self): def test_get_audiobook_bad_urn(self):
with self.assertRaises(SpotifyException): with self.assertRaises(SpotifyException):
self.spotify.get_audiobook("bogus_urn", market="US") self.spotify.get_audiobook("bogus_urn", market="US")
def test_get_audiobooks(self): def test_get_audiobooks(self):
results = self.spotify.get_audiobooks(self.four_books, market="US") results = self.spotify.get_audiobooks(self.two_books, market="US")
self.assertTrue('audiobooks' in results) self.assertTrue('audiobooks' in results)
self.assertTrue(len(results['audiobooks']) == 4) self.assertTrue(len(results['audiobooks']) == 2)
self.assertTrue(results['audiobooks'][0]['name'] == self.assertTrue(results['audiobooks'][0]['name']
'American Gods: The Tenth Anniversary Edition: A Novel') == 'Dune: Book One in the Dune Chronicles')
self.assertTrue(results['audiobooks'][1]['name'] == 'The Da Vinci Code: A Novel') self.assertTrue(results['audiobooks'][1]['name'] == 'The Helper')
self.assertTrue(results['audiobooks'][2]['name'] == 'Outlander')
self.assertTrue(results['audiobooks'][3]['name'] == 'Pachinko: A Novel')
def test_get_audiobook_chapters(self): def test_get_audiobook_chapters(self):
results = self.spotify.get_audiobook_chapters( results = self.spotify.get_audiobook_chapters(
self.american_gods_urn, market="US", limit=10, offset=5) self.dune_urn, market="US", limit=10, offset=5)
self.assertTrue('items' in results) self.assertTrue('items' in results)
self.assertTrue(len(results['items']) == 10) self.assertTrue(len(results['items']) == 10)
self.assertTrue(results['items'][0]['chapter_number'] == 5) self.assertTrue(results['items'][0]['chapter_number'] == 5)