From 4b8d068ec43e8f656f08a2a232575ade75e98233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bruckert?= Date: Sun, 23 Jun 2024 19:58:35 +0100 Subject: [PATCH] Search audiobooks --- tests/integration/non_user_endpoints/test.py | 43 +++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/tests/integration/non_user_endpoints/test.py b/tests/integration/non_user_endpoints/test.py index c67703a6..6b91b3e5 100644 --- a/tests/integration/non_user_endpoints/test.py +++ b/tests/integration/non_user_endpoints/test.py @@ -60,15 +60,14 @@ class AuthTestSpotipy(unittest.TestCase): heavyweight_ep1_url = 'https://open.spotify.com/episode/68kq3bNz6hEuq8NtdfwERG' reply_all_ep1_urn = 'spotify:episode:1KHjbpnmNpFmNTczQmTZlR' - american_gods_urn = 'spotify:audiobook:1IcM9Untg6d3ktuwObYGcN' - american_gods_id = '1IcM9Untg6d3ktuwObYGcN' - american_gods_url = 'https://open.spotify.com/audiobook/1IcM9Untg6d3ktuwObYGcN' - - four_books = [ - 'spotify:audiobook:1IcM9Untg6d3ktuwObYGcN', - 'spotify:audiobook:37sRC6carIX2Vf3Vv716T7', - 'spotify:audiobook:1Gep4UJ95xQawA55OgRI8n', - 'spotify:audiobook:4Sm381mcf5gBsi9yfhqgVB'] + # The following audiobooks are currently available in the GB market + # but might not be in other markets + dune_urn = 'spotify:audiobook:7iHfbu1YPACw6oZPAFJtqe' + dune_id = '7iHfbu1YPACw6oZPAFJtqe' + dune_url = 'https://open.spotify.com/audiobook/7iHfbu1YPACw6oZPAFJtqe' + two_books = [ + 'spotify:audiobook:7iHfbu1YPACw6oZPAFJtqe', + 'spotify:audiobook:67VtmjZitn25TWocsyAEyh'] @classmethod def setUpClass(self): @@ -337,7 +336,7 @@ def test_artist_albums(self): def find_album(): 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 False @@ -484,28 +483,32 @@ def test_available_markets(self): self.assertIn("US", markets) self.assertIn("GB", markets) + def test_artist_search(self): + results = self.spotify.search(q='test', type='audiobook') + from pprint import pprint + pprint(results) + self.assertTrue('audiobooks' in results) + 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'] == - 'American Gods: The Tenth Anniversary Edition: A Novel') + 'Dune: Book One in the Dune Chronicles') def test_get_audiobook_bad_urn(self): with self.assertRaises(SpotifyException): self.spotify.get_audiobook("bogus_urn", market="US") 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(len(results['audiobooks']) == 4) - self.assertTrue(results['audiobooks'][0]['name'] == - 'American Gods: The Tenth Anniversary Edition: A Novel') - self.assertTrue(results['audiobooks'][1]['name'] == 'The Da Vinci Code: A Novel') - self.assertTrue(results['audiobooks'][2]['name'] == 'Outlander') - self.assertTrue(results['audiobooks'][3]['name'] == 'Pachinko: A Novel') + self.assertTrue(len(results['audiobooks']) == 2) + self.assertTrue(results['audiobooks'][0]['name'] + == 'Dune: Book One in the Dune Chronicles') + self.assertTrue(results['audiobooks'][1]['name'] == 'The Helper') def test_get_audiobook_chapters(self): 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(len(results['items']) == 10) self.assertTrue(results['items'][0]['chapter_number'] == 5)