add testing to fastapi

This commit is contained in:
Thomas Peetz
2025-04-17 02:21:14 +02:00
parent 4a61d6a727
commit a6eeea6c1f
11 changed files with 156 additions and 14 deletions
+36
View File
@@ -0,0 +1,36 @@
from typing import List, Dict
from uuid import UUID
from pydantic import BaseModel
from app.schema import Artist
class ArtistCreation(BaseModel):
name: str
class ArtistResponse(BaseModel):
id: UUID
name: str
class ArtistDetailResponse(BaseModel):
id: UUID
name: str
works: Dict[str, List[str]]
def get_artist_details(artist: Artist) -> ArtistDetailResponse:
works = {}
for work in artist.comic_works:
work_type = work.work_type.name
comic_title = work.comic.title
if work_type in works:
works[work_type].append(comic_title)
else:
works[work_type] = [comic_title]
response = ArtistDetailResponse(
id=artist.id,
name=artist.name,
works=works
)
return response
+46
View File
@@ -0,0 +1,46 @@
from typing import List, Dict
from uuid import UUID
from pydantic import BaseModel
from app.schema import Comic
class ComicResponse(BaseModel):
id: UUID
title: str
completed: bool
class ComicDetailsResponse(BaseModel):
id: UUID
title: str
completed : bool
current_order : bool
publisher: str
volumes: List[str]
works: Dict[str, List[str]]
def get_comic_details(comic: Comic) -> ComicDetailsResponse | None:
volumes = []
for volume in comic.volumes:
volumes.append(volume.name)
works = {}
for work in comic.comic_works:
work_type = work.work_type.name
artist_name = work.artist.name
if work_type in works:
works[work_type].append(artist_name)
else:
works[work_type] = [artist_name]
response = ComicDetailsResponse(
id=comic.id,
title=comic.title,
completed=(comic.completed == 1),
current_order=(comic.current_order == 1),
publisher=comic.publisher.name,
volumes=volumes,
works=works
)
return response
@@ -3,8 +3,7 @@ from uuid import UUID
from pydantic import BaseModel
class ComicResponse(BaseModel):
class SportResponse(BaseModel):
id: UUID
title: str
completed: bool
name: str