This commit is contained in:
+19
-2
@@ -1,10 +1,11 @@
|
||||
"""Stand-in Spotify Web API: just enough of /api/token, .../player/devices
|
||||
and .../player to test spotify.py against, the same way fakes.py stands in
|
||||
"""Stand-in Spotify Web API: just enough of /api/token, .../player/devices,
|
||||
.../player and .../player/seek to test spotify.py against, the same way fakes.py stands in
|
||||
for real HEOS hardware."""
|
||||
|
||||
import json
|
||||
import threading
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
|
||||
class FakeSpotify(threading.Thread):
|
||||
@@ -21,6 +22,7 @@ class FakeSpotify(threading.Thread):
|
||||
self.valid_token = None
|
||||
self.tokens_issued = 0
|
||||
self.transfers = [] # every PUT /v1/me/player body
|
||||
self.seeks = [] # every PUT /v1/me/player/seek's position_ms
|
||||
self.reject_refresh = False # simulate a revoked refresh token
|
||||
self.player = None # GET /v1/me/player's body; None is no session (204)
|
||||
|
||||
@@ -63,6 +65,21 @@ class FakeSpotify(threading.Thread):
|
||||
self.send_response(204)
|
||||
self.end_headers()
|
||||
return
|
||||
if self.path.startswith("/v1/me/player/seek?"):
|
||||
if not self._authorized():
|
||||
self._send(401, {"error": {"message": "The access token expired"}})
|
||||
return
|
||||
query = parse_qs(urlparse(self.path).query)
|
||||
fake.seeks.append(int(query["position_ms"][0]))
|
||||
# The real one answers some player commands with a
|
||||
# non-JSON body rather than an empty 204.
|
||||
body = b"a1b2c3d4"
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
return
|
||||
self._send(404, {"error": {"message": "not found"}})
|
||||
|
||||
def do_GET(self):
|
||||
|
||||
Reference in New Issue
Block a user