-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
63 lines (51 loc) · 1.55 KB
/
test_app.py
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
import pytest
from app import app
import data
@pytest.fixture
def client():
app.config["TESTING"] = True
with app.test_client() as client:
yield client
@pytest.fixture
def turn_data():
return {
"game": {"id": "game-id-string"},
"turn": 4,
"board": {
"height": 15,
"width": 15,
"food": [{"x": 1, "y": 3}],
"snakes": [
{
"id": "snake-id-string",
"name": "Sneky Snek",
"health": 90,
"body": [{"x": 1, "y": 3}],
}
],
},
"you": {
"id": "snake-id-string",
"name": "Sneky Snek",
"health": 90,
"body": [{"x": 1, "y": 3}],
},
}
def test_start(client, turn_data):
res = client.post("/start", json=turn_data,)
assert res.status_code == 200
assert res.headers["content-type"] == "application/json"
json_data = res.get_json()
assert json_data["color"]
assert json_data["headType"]
assert json_data["tailType"]
def test_end(client, turn_data):
res = client.post("/end", json=turn_data,)
assert res.status_code == 200
assert res.headers["content-type"] == "application/json"
def test_move(client, turn_data):
res = client.post("/move", json=turn_data,)
assert res.status_code == 200
assert res.headers["content-type"] == "application/json"
json_data = res.get_json()
assert json_data["move"] in [data.UP, data.DOWN, data.LEFT, data.RIGHT]