infiniteradio / tests /test_api.py
JonCard's picture
Claude Opus 5.5
Add Infinite Radio server for Hugging Face Spaces
ab98ae3
Raw History Blame Contribute Delete
1.36 kB
import pytest
from app.state import radio_state
def test_player_page(client):
response = client.get("/")
assert response.status_code == 200
assert response.headers["content-type"].startswith("text/html")
assert "stream" in response.text
@pytest.mark.parametrize("tempo", [40, 120, 150])
def test_put_tempo_updates_state(client, tempo):
assert client.put(f"/tempo/{tempo}").status_code == 200
assert radio_state.snapshot()[0].tempo == tempo
@pytest.mark.parametrize("tempo", ["39", "151", "fast"])
def test_put_tempo_rejects_invalid(client, tempo):
before = radio_state.snapshot()
assert client.put(f"/tempo/{tempo}").status_code == 422
assert radio_state.snapshot() == before
def test_post_tempo_not_allowed(client):
assert client.post("/tempo/100").status_code == 405
@pytest.mark.parametrize("spookiness", [0, 73, 100])
def test_post_style_updates_state(client, spookiness):
assert client.post("/style", json={"spookiness": spookiness}).status_code == 200
assert radio_state.snapshot()[0].spookiness == spookiness
@pytest.mark.parametrize("body", [None, {}, {"spookiness": -1}, {"spookiness": 101}])
def test_post_style_rejects_invalid(client, body):
before = radio_state.snapshot()
assert client.post("/style", json=body).status_code == 422
assert radio_state.snapshot() == before