-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.py
64 lines (53 loc) · 1.99 KB
/
test_api.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
from fastapi.testclient import TestClient
from main import app
def test_root():
with TestClient(app) as client:
response = client.get("/")
assert response.status_code == 200
assert response.json() == "Hi, Welcome to Census API"
def test_prediction_negative_prediction():
with TestClient(app) as client:
response = client.post(
"/predict",
json={
"age": 39,
"workclass": "State-gov",
"fnlgt": 77516,
"education": "Bachelors",
"education-num": 13,
"marital-status": "Never-married",
"occupation": "Adm-clerical",
"relationship": "Not-in-family",
"race": "White",
"sex": "Male",
"capital-gain": 2174,
"capital-loss": 0,
"hours-per-week": 40,
"native-country": "United-States"
},
)
assert response.status_code == 200
assert response.json() == {"prediction": {"salary": "<=50K"}}
def test_prediction_positive_prediction():
with TestClient(app) as client:
response = client.post(
"/predict",
json={
"age": 52,
"workclass": "Self-emp-not-inc",
"fnlgt": 209642,
"education": "HS-grad",
"education-num": 9,
"marital-status": "Married-civ-spouse",
"occupation": "Exec-managerial",
"relationship": "Husband",
"race": "White",
"sex": "Male",
"capital-gain": 0,
"capital-loss": 0,
"hours-per-week": 45,
"native-country": "United-States"
},
)
assert response.status_code == 200
assert response.json() == {"prediction": {"salary": ">50K"}}