This commit is contained in:
+34
-2
@@ -9,7 +9,7 @@ from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from spotify import SpotifyClient, SpotifyError # noqa: E402
|
||||
from spotify import SpotifyClient, SpotifyDeviceUnavailable, SpotifyError # noqa: E402
|
||||
from tests.fake_spotify import FakeSpotify # noqa: E402
|
||||
|
||||
|
||||
@@ -33,10 +33,33 @@ class SpotifyTest(unittest.TestCase):
|
||||
self.assertEqual(self.fake.transfers, [{"device_ids": ["dev-1"], "play": True}])
|
||||
|
||||
def test_resume_raises_when_no_device_has_that_name(self):
|
||||
with self.assertRaises(SpotifyError):
|
||||
with self.assertRaises(SpotifyDeviceUnavailable):
|
||||
self.client.resume("Kitchen")
|
||||
self.assertEqual(self.fake.transfers, [])
|
||||
|
||||
def test_an_invisible_device_reports_what_it_looked_for(self):
|
||||
# A room another Spotify account is signed in to is simply absent
|
||||
# here, and app.py needs the name back to go and ask who has it.
|
||||
with self.assertRaises(SpotifyDeviceUnavailable) as caught:
|
||||
self.client.resume("Living Room")
|
||||
self.assertEqual(caught.exception.device_name, "Living Room")
|
||||
|
||||
def test_it_knows_what_its_login_is_allowed_to_do(self):
|
||||
# Signing a speaker in needs the "streaming" scope, and finding that
|
||||
# out afterwards costs the room -- see app.py's _spotify_take_over.
|
||||
self.fake.scope = "user-read-playback-state streaming"
|
||||
self.assertTrue(self.client.has_scope("streaming"))
|
||||
self.assertFalse(self.client.has_scope("user-modify-playback-state"))
|
||||
|
||||
def test_pause_stops_what_the_account_is_playing(self):
|
||||
# What handing a room back starts with: the account keeps its place
|
||||
# in the queue, so its own app -- or this panel's button -- can pick
|
||||
# the stream up again somewhere else.
|
||||
self.fake.player = {"device": {"id": "dev-1", "name": "Lego Room"}, "is_playing": True}
|
||||
self.client.pause()
|
||||
self.assertEqual(self.fake.pauses, 1)
|
||||
self.assertFalse(self.client.playback()["is_playing"])
|
||||
|
||||
def test_seek_asks_for_the_position(self):
|
||||
self.client.seek(90000)
|
||||
self.assertEqual(self.fake.seeks, [90000])
|
||||
@@ -60,6 +83,15 @@ class SpotifyTest(unittest.TestCase):
|
||||
self.assertEqual(names, ["Lego Room", "Home Cinema"])
|
||||
self.assertEqual(self.fake.tokens_issued, 2)
|
||||
|
||||
def test_a_plain_text_refusal_is_quoted_rather_than_flattened(self):
|
||||
# The 403 for an account missing from the developer app's User
|
||||
# Management is Spotify's only hint that that is what is wrong,
|
||||
# and it arrives as prose rather than as a JSON error object.
|
||||
self.fake.forbid = "The user is not registered for this application."
|
||||
with self.assertRaises(SpotifyError) as caught:
|
||||
self.client.devices()
|
||||
self.assertIn("not registered for this application", str(caught.exception))
|
||||
|
||||
def test_a_revoked_refresh_token_raises_a_clear_error(self):
|
||||
self.fake.reject_refresh = True
|
||||
with self.assertRaises(SpotifyError):
|
||||
|
||||
Reference in New Issue
Block a user