Feat: add unhappy path test for post student

This commit is contained in:
2022-12-29 07:37:49 +01:00
parent febe686688
commit c7eb8e44d2
3 changed files with 40 additions and 8 deletions

View File

@@ -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)

View File

@@ -52,7 +52,7 @@ class TribeSQLiteRepository(AbstractRepository):
if row:
return Tribe(*row)
raise ValueError(f"The tribe {name} does not exists")
raise TribeRepositoryError(f"The tribe {name} does not exists")
def list(self) -> list[Tribe]:
cursor = self.conn.cursor()