Skip to content

Commit

Permalink
Added few options to show FastAPI functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo.arenas committed Feb 11, 2021
1 parent 89b6c1b commit 84ce11e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion routes/home.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from fastapi import APIRouter

app_home = APIRouter()


@app_home.get('/', tags=["Intro"])
async def hello():
return {"message": "Hello!"}


@app_home.get('/bye', tags=["Intro"])
async def bye():
return {"message": "Bye!"}
4 changes: 3 additions & 1 deletion routes/v1/iris_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

@app_iris_predict_v1.post('/iris/predict',
tags=["Predictions"],
response_model=IrisPredictionResponse)
response_model=IrisPredictionResponse,
description="Get a classification from Iris")
async def get_prediction(iris: Iris):
data = dict(iris)['data']
prediction = clf.model.predict(data).tolist()
Expand All @@ -16,3 +17,4 @@ async def get_prediction(iris: Iris):
return {"prediction": prediction,
"probability": probability,
"log_probability": log_probability}

9 changes: 9 additions & 0 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def test_success_prediction():
response_json = response.json()
assert response.status_code == 200
assert 'prediction' in response_json


def test_bad_request():
endpoint = '/v1/iris/predict'
body = {"data": [[4.8, 3, 1.4], [2, 1, 3.2, 1.1]]}

with TestClient(app) as client:
response = client.post(endpoint, json=body)
assert response.status_code == 422

0 comments on commit 84ce11e

Please sign in to comment.