forked from zjesko/mlops-iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
58 lines (52 loc) · 1.92 KB
/
test_app.py
File metadata and controls
58 lines (52 loc) · 1.92 KB
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
# test to check the correct functioning of the /ping route
def test_ping():
with TestClient(app) as client:
response = client.get("/ping")
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["ping"] == "pong"
# test to check if Iris Virginica is classified correctly
def test_pred_virginica():
# defining a sample payload for the testcase
payload = {
"sepal_length": 3,
"sepal_width": 5,
"petal_length": 3.2,
"petal_width": 4.4,
}
with TestClient(app) as client:
response = client.post("/predict_flower", json=payload)
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["flower_class"] == "Iris Virginica"
# task 2
# test to check if Iris Setosa is classified correctly
def test_pred_setosa():
# defining a sample payload for the testcase
payload = {
"sepal_length": 5.1,
"sepal_width": 3.5,
"petal_length": 1.4,
"petal_width": 0.2,
}
with TestClient(app) as client:
response = client.post("/predict_flower", json=payload)
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["flower_class"] == "Iris Setosa"
# test to check if Iris Versicolour is classified correctly
def test_pred_versicolour():
# defining a sample payload for the testcase
payload = {
"sepal_length": 7,
"sepal_width": 3.2,
"petal_length": 4.7,
"petal_width": 1.4,
}
with TestClient(app) as client:
response = client.post("/predict_flower", json=payload)
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["flower_class"] == "Iris Versicolour"