Feat: add unhappy path test for post student
This commit is contained in:
@@ -65,8 +65,20 @@ async def get_tribe(name: str):
|
||||
|
||||
@app.post("/students", status_code=status.HTTP_201_CREATED, response_model=StudentModel)
|
||||
async def post_student(item: StudentModel):
|
||||
if item.id is not None:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
content=f"You can't post a student with an id. It is already registrered. Use PUT to modify it.",
|
||||
)
|
||||
|
||||
tribe_name = item.tribe_name
|
||||
tribe = tribe_repo.get(tribe_name)
|
||||
try:
|
||||
tribe = tribe_repo.get(tribe_name)
|
||||
except TribeRepositoryError:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
content=f"The tribe {tribe_name} does not exists. You can't add a student in it.",
|
||||
)
|
||||
|
||||
student = Student(item.name, tribe)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user