-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
54 lines (48 loc) · 2.13 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
def test_get(client):
r = client.get("/")
assert r.status_code == 200
assert r.json() == {"message": "Greetings!"}
def test_post_high(client):
request = client.post("/", json={'age': 33,
'workclass': 'Private',
'fnlgt': 149184,
'education': 'HS-grad',
'marital_status': 'Never-married',
'occupation': 'Prof-specialty',
'relationship': 'Not-in-family',
'race': 'White',
'sex': 'Male',
'hoursPerWeek': 60,
'nativeCountry': 'United-States'
})
assert request.status_code == 200
assert request.json() == {"prediction": ">50K"}
def test_post_low(client):
request = client.post("/", json={'age': 19,
'workclass': 'Private',
'fnlgt': 149184,
'education': 'HS-grad',
'marital_status': 'Never-married',
'occupation': 'Prof-specialty',
'relationship': 'Not-in-family',
'race': 'White',
'sex': 'Male',
'hoursPerWeek': 60,
'nativeCountry': 'United-States'
})
assert request.status_code == 200
assert request.json() == {"prediction": "<=50K"}
def test_post_malformed(client):
r = client.post("/", json={
"age": 32,
"workclass": "",
"education": "Some-college",
"maritalStatus": "",
"occupation": "",
"relationship": "Husband",
"race": "Black",
"sex": "Male",
"hoursPerWeek": 60,
"nativeCountry": "United-States"
})
assert r.status_code == 422