-
Notifications
You must be signed in to change notification settings - Fork 2
/
flaskAPI_test.py
52 lines (43 loc) · 1.47 KB
/
flaskAPI_test.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
from flaskAPI import app, db
from flask import json
from assertpy import assert_that
def test_get_games_list():
response = app.test_client().get('/gameslist')
data = json.loads(response.get_data(as_text=True))
print(data)
assert response.status_code == 200
completion = data[0]["completion"]
levels = data[0]["levels"]
title = data[0]["title"]
assert_that(completion).is_not_empty()
assert_that(levels).is_not_empty()
assert_that(title).is_not_empty()
def test_post_game():
test_game = {
"title": "tonys test game",
"description": "this is a test game to seed the database",
"completion": "well done you have completed the game",
"levels": [
{
"wincondition": "text",
"mainclue": "just write hello",
"clue2": "nothing",
"clue3": "nothing again",
"wintext": "you have won this level",
"windata": "hello"
},
{
"wincondition": "text",
"mainclue": "just write hello",
"clue2": "nothing",
"clue3": "nothing again",
"wintext": "you have won this level",
"windata": "hello"
}
]
}
response = app.test_client().post('/games', json=test_game)
data = json.loads(response.get_data(as_text=True))
print(data)
assert response.status_code == 200
print(data)