music-app/backend/tests/test_routers_shareplay.py
Jarian Cottingham 5c283eceef chore: remove test artifacts, fix hardcoded paths, ruff clean, license
- Remove committed .coverage and test-results/ (196K screenshots); gitignore them
- Fix hardcoded  /home/userpath + venv/bin/python in test_endpoints.py
  (relative backend dir + sys.executable)
- Fix concatenated 'import json' in settings.py; bare excepts -> Exception;
  SQLAlchemy-safe is_active.is_(True); __all__ on models/schemas barrels
- ruff clean (93 fixes), MIT LICENSE, PLAN.md -> docs/, README Tests section
- 300 tests pass, 93.7% coverage
2026-08-20 21:34:15 +00:00

78 lines
2.7 KiB
Python

"""Router tests - SharePlay endpoints."""
class TestCreateRoom:
def test_create(self, client):
r = client.post("/api/shareplay/create")
assert r.status_code == 200
data = r.json()
assert "id" in data
assert data["creator_user"] == "user"
assert data["active_connections"] == 1
class TestJoinRoom:
def test_join(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/join", json={"room_id": room_id})
assert r.status_code == 200
assert r.json()["active_connections"] == 2
def test_join_not_found(self, client):
r = client.post("/api/shareplay/join", json={"room_id": "nonexistent"})
assert r.status_code == 404
class TestLeaveRoom:
def test_leave(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/leave", json={"room_id": room_id})
assert r.status_code == 200
def test_leave_not_found(self, client):
r = client.post("/api/shareplay/leave", json={"room_id": "nonexistent"})
assert r.status_code == 404
class TestCue:
def test_get_cue(self, client):
r = client.get("/api/shareplay/cue?room_id=test")
assert r.status_code == 200
data = r.json()
assert "items" in data
assert "next_song" in data
class TestControl:
def test_play(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={"room_id": room_id, "type": "play"})
assert r.status_code == 200
def test_pause(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={"room_id": room_id, "type": "pause"})
assert r.status_code == 200
def test_seek(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={
"room_id": room_id, "type": "seek", "payload": {"position": 42}
})
assert r.status_code == 200
def test_shuffle(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={"room_id": room_id, "type": "shuffle"})
assert r.status_code == 200
def test_control_not_found(self, client):
r = client.post("/api/shareplay/control", json={"room_id": "x", "type": "play"})
assert r.status_code == 404