-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
58 lines (52 loc) · 1.86 KB
/
test_main.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
from fastapi.testclient import TestClient
from main import app
# Instantiate the testing client with our app.
client = TestClient(app)
def test_api_welcome_message_root():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"Greetings": "Welcome to Income Prediction Model API"}
def test_positive_prediction():
response = client.post(
"/person/",
json={"age": 43,
"workclass": "Private",
"fnlgt": 292175,
"education": "Masters",
"education-num": 14,
"marital-status": "Divorced",
"occupation": "Exec-managerial",
"relationship": "Not-in-family",
"race": "White",
"sex": "Female",
"capital-gain": 5,
"capital-loss": 0,
"hours-per-week": 45,
"native-country": "United-States"},
)
assert response.status_code == 200
assert response.json() == {
"prediction": 1
}
def test_negative_prediction():
response = client.post(
"/person/",
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": 0
}