From f94a89a995d755e7fd8a665994c5f6bb6d2f2d2f Mon Sep 17 00:00:00 2001 From: Brandon Parrott <107897092+bparrott3@users.noreply.github.com> Date: Fri, 31 May 2024 09:46:19 -0700 Subject: [PATCH] Add unit tests for queue functions (#1059) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update test.py Add tests for queue manipulation/retrieval functions * Update CHANGELOG.md * flake8 --------- Co-authored-by: Stéphane Bruckert --- CHANGELOG.md | 2 +- tests/integration/user_endpoints/test.py | 41 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d67ad09..3d498943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Add your changes below. ### Added -- +- Added unit tests for queue functions ### Fixed - diff --git a/tests/integration/user_endpoints/test.py b/tests/integration/user_endpoints/test.py index 93955e73..fb1fbb21 100644 --- a/tests/integration/user_endpoints/test.py +++ b/tests/integration/user_endpoints/test.py @@ -558,3 +558,44 @@ def test_current_user(self): c_user = self.spotify.current_user() user = self.spotify.user(c_user['id']) self.assertEqual(c_user['display_name'], user['display_name']) + + +class SpotifyQueueApiTests(unittest.TestCase): + + @classmethod + def setUp(self): + self.spotify = Spotify(auth="test_token") + + def test_get_queue(self, mock_get): + # Mock the response from _get + mock_get.return_value = {'songs': ['song1', 'song2']} + + # Call the queue function + response = self.spotify.queue() + + # Check if the correct endpoint is called + mock_get.assert_called_with("me/player/queue") + + # Check if the response is as expected + self.assertEqual(response, {'songs': ['song1', 'song2']}) + + def test_add_to_queue(self, mock_post): + test_uri = 'spotify:track:123' + + # Call the add_to_queue function + self.spotify.add_to_queue(test_uri) + + # Check if the correct endpoint is called + endpoint = "me/player/queue?uri=%s" % test_uri + mock_post.assert_called_with(endpoint) + + def test_add_to_queue_with_device_id(self, mock_post): + test_uri = 'spotify:track:123' + device_id = 'device123' + + # Call the add_to_queue function with a device_id + self.spotify.add_to_queue(test_uri, device_id=device_id) + + # Check if the correct endpoint is called + endpoint = "me/player/queue?uri=%s&device_id=%s" % (test_uri, device_id) + mock_post.assert_called_with(endpoint)