Implenting unit testing"
This commit is contained in:
28
main.py
28
main.py
@@ -2,42 +2,42 @@ from fastapi import FastAPI
|
||||
|
||||
from typing import List
|
||||
|
||||
from back.schemas import PeopleCreate, AverageAgeByCountry, CountByCountry, GenderRepartition
|
||||
from back.schemas import PeopleList, AverageAgeByCountry, CountByCountry, GenderRepartition
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.post("/people")
|
||||
async def create_people(people_list: PeopleCreate) -> dict:
|
||||
async def create_people(people_list: PeopleList) -> dict:
|
||||
return {
|
||||
"message": "People list has been succesfully imported",
|
||||
"records_created": 12
|
||||
"records_created": 10
|
||||
}
|
||||
|
||||
|
||||
@app.get("/average_age", response_model=List[AverageAgeByCountry])
|
||||
async def read_average_age(name: str):
|
||||
async def read_average_age() -> List[AverageAgeByCountry]:
|
||||
return [
|
||||
{'country': 'FR', 'average_age': 22.7},
|
||||
{'country': 'BE', 'average_age': 14.7},
|
||||
{'country': 'DE', 'average_age': 27.7},
|
||||
{'country': 'IT', 'average_age': 32.7},
|
||||
{'country': 'FR', 'average_age': 15.0},
|
||||
{'country': 'BE', 'average_age': 25.0},
|
||||
{'country': 'DE', 'average_age': 23.3},
|
||||
{'country': 'IT', 'average_age': 45.0},
|
||||
]
|
||||
|
||||
|
||||
@app.get("/count_by_country", response_model=List[CountByCountry])
|
||||
async def read_count_by_country():
|
||||
async def read_count_by_country() -> List[CountByCountry]:
|
||||
return [
|
||||
{'country': 'FR', 'people_count': 2},
|
||||
{'country': 'BE', 'people_count': 4},
|
||||
{'country': 'DE', 'people_count': 3},
|
||||
{'country': 'IT', 'people_count': 7},
|
||||
{'country': 'IT', 'people_count': 1},
|
||||
]
|
||||
|
||||
|
||||
@app.get("/count_by_gender/{country}", response_model=GenderRepartition)
|
||||
async def read_count_by_gender(country: str):
|
||||
@app.get("/gender_repartition/{country}", response_model=GenderRepartition)
|
||||
async def read_count_by_gender(country: str) -> GenderRepartition:
|
||||
return {
|
||||
"female_proportion": 51.2,
|
||||
"male_proportion": 48.8
|
||||
"female_proportion": 33.3,
|
||||
"male_proportion": 66.6
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user