-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive_api_test.py
72 lines (54 loc) · 2.18 KB
/
live_api_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
import requests
hekoru_endpoint = 'https://mlopsp3.herokuapp.com/'
def test_api_live_get_predictions_inf1():
""" Test Fast API predict route with a '<=50K' salary prediction result """
r = requests.post('https://mlopsp3.herokuapp.com/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 r.status_code == 200
assert r.json() == {"prediction": {"salary": "<=50K"}}
return r.json()["prediction"]
def test_api_live_get_predictions_inf2():
""" Test Fast API predict route with a '>50K' salary prediction result """
r = requests.post('https://mlopsp3.herokuapp.com/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 r.status_code == 200
assert r.json() == {"prediction": {"salary": ">50K"}}
return r.json()["prediction"]
if __name__ == "__main__":
# Call live testing function
print("test_api_live_get_predictions_inf1 ...")
res = test_api_live_get_predictions_inf1()
print(res)
print("test_api_live_get_predictions_inf2 ...")
res = test_api_live_get_predictions_inf2()
print(res)