-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_routes.py
More file actions
75 lines (53 loc) · 1.99 KB
/
Copy pathtest_routes.py
File metadata and controls
75 lines (53 loc) · 1.99 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
def test_homepage(client):
response = client.get('/')
assert response.status_code == 200
assert b'Pretty Lights' in response.data
assert b'/static/scripts.js' in response.data
def test_state(client):
response = client.get('/state')
assert response.status_code == 200
data = json.loads(response.data)
assert data['multipler'] == 'SINGLE_COLOR'
assert data['colors'][0]['hue'] == 100
def test_lock(client, redis_client):
response = client.post('/lock')
assert response.status_code == 201
redis_client.set.assert_called()
def test_unlock(client, redis_client):
response = client.delete('/lock')
assert response.status_code == 204
redis_client.set.assert_called()
def test_random_single(client):
response = client.post('/random/single')
assert response.status_code == 200
def test_random_unknown_type(client):
response = client.post('/random/unknown')
assert response.status_code == 400
def test_random_automated_when_idle(client, redis_client):
redis_client.get.return_value = json.dumps({
'lastModified': 0,
'colors': [{'hue': 100, 'sat': 255, 'lum': 255}],
'multipler': 'SINGLE_COLOR',
'animation': None,
'lockedBy': None,
})
response = client.post('/random/single?automated=1')
assert response.status_code == 200
def test_lights(client):
payload = {
'multiplier': 'columns',
'colors': [{'hue': 10, 'sat': 255, 'lum': 255}],
}
response = client.post('/lights', json=payload)
assert response.status_code == 200
def test_lights_no_colors(client):
payload = {'multiplier': 'columns', 'colors': []}
response = client.post('/lights', json=payload)
assert response.status_code == 400
def test_animation(client):
response = client.post('/animations/breathing')
assert response.status_code == 200
def test_animation_unknown(client):
response = client.post('/animations/does-not-exist')
assert response.status_code == 400