-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
80 lines (66 loc) · 1.93 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
File to test the api
"""
import json
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_welcome_message():
"""
Test case to check root of the api
"""
response = client.get("/")
assert response.status_code == 200
assert response.json() == "Welcome!"
def test_less_than_50():
"""
Test case to check for predictions less than 50
"""
data = {
"workclass": "state_gov",
"education": "bachelors",
"marital_status": "never_married",
"occupation": "adm_clerical",
"relationship": "not_in_family",
"race": "white",
"sex": "male",
"native_country": "united_states",
"age": 39,
"fnlgt": 77516,
"education_num": 13,
"capital_gain": 2174,
"capital_loss": 0,
"hours_per_week": 40,
}
response = client.post("/predict", data=json.dumps(data))
assert response.status_code == 200
assert response.json() == {'pred': '<=50K'}
def test_greater_than_50():
"""
Test case to check for predictions greater than 50
"""
data = {"age": 52,
"workclass": "Self-emp-inc",
"fnlgt": 287927,
"education": "HS-grad",
"education_num": 9,
"marital_status": "Married-civ-spouse",
"occupation": "Exec-managerial",
"relationship": "Wife",
"race": "White",
"sex": "Female",
"capital_gain": 15024,
"capital_loss": 0,
"hours_per_week": 40,
"native_country": "United-States"
}
response = client.post("/predict", data=json.dumps(data))
assert response.status_code == 200
assert response.json() == {'pred': '>50K'}
def test_post_empty_data():
"""
Test case to check empty data
"""
data = {}
response = client.post("/predict", data=data)
assert response.status_code == 422