Skip to content

Commit

Permalink
Add integration tests for audiobook endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
danhjoseph committed Oct 31, 2023
1 parent b599fd8 commit 1231a18
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added support for audiobook endpoints: get_audiobook, get_audiobooks, and get_audiobook_chapters.
- Added integration tests for audiobook endpoints.
- Removed `python 2.7` from GitHub Actions CI workflow. Python v2.7 reached end of life support and is no longer supported by Ubuntu 20.04.
- Removed `python 3.6` from GitHub Actions CI workflow. Ubuntu 20.04 is not available in GitHub Actions for `python 3.6`.

Expand Down
38 changes: 38 additions & 0 deletions tests/integration/non_user_endpoints/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ 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']

@classmethod
def setUpClass(self):
self.spotify = Spotify(
Expand Down Expand Up @@ -455,3 +465,31 @@ def test_available_markets(self):
self.assertTrue(isinstance(markets, list))
self.assertIn("US", markets)
self.assertIn("GB", markets)

def test_get_audiobook(self):
audiobook = self.spotify.get_audiobook(self.american_gods_urn, market="US")
print(audiobook)
self.assertTrue(audiobook['name'] ==
'American Gods: The Tenth Anniversary Edition: A Novel')

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")
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')

def test_get_audiobook_chapters(self):
results = self.spotify.get_audiobook_chapters(
self.american_gods_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)
self.assertTrue(results['items'][9]['chapter_number'] == 14)

0 comments on commit 1231a18

Please sign in to comment.