File size: 1,357 Bytes
ab98ae3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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