-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
50 lines (34 loc) · 1.27 KB
/
test_app.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
from fastapi.testclient import TestClient
import pytest
from app import app
from pydantic import BaseModel # pylint: disable=no-name-in-module
class IrisFeatures(BaseModel):
"""Iris features model."""
features: list
class Item(BaseModel):
"""Item model."""
message: str
client = TestClient(app)
def test_root():
"""Test the root route."""
response = client.get("/")
assert response.status_code == 200
expected = {"message": "API is Working!"}
assert response.json() == expected
def test_echo():
"""Test the echo route."""
response = client.post("/echo", json={"message": "Hello, World!"})
assert response.status_code == 200
expected = {"echo": "Hello, World!"}
assert response.json() == expected
def test_train():
"""Test the train route."""
response = client.post("/train")
assert response.status_code == 200
# Expected prediction is not defined, as we don't know what the model will return
def test_predict():
"""Test the predict route."""
iris_features = {"features": [5.1, 3.5, 1.4, 0.2]} # Example iris features
response = client.post("/predict", json=iris_features)
assert response.status_code == 200
# Expected prediction is not defined, as we don't know what the model will return