Skip to content

Commit

Permalink
fixed for no arrays in rest bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
ychebyshev committed Feb 1, 2024
1 parent 81515d7 commit 6f49070
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 9 additions & 0 deletions shvatka/api/models/responses.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import typing
from dataclasses import dataclass, field
from datetime import datetime
from typing import Sequence, Generic

from shvatka.core.models import dto
from shvatka.core.models.dto import scn
from shvatka.core.models.enums import GameStatus

T = typing.TypeVar("T")


@dataclass
class Page(Generic[T]):
content: Sequence[T]


@dataclass
class Player:
Expand Down
8 changes: 3 additions & 5 deletions shvatka/api/routes/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Sequence

from fastapi import APIRouter
from fastapi.params import Depends, Path

Expand All @@ -14,7 +12,7 @@ async def get_my_games_list(
player: dto.Player = Depends(player_provider), # type: ignore[assignment]
dao: HolderDao = Depends(dao_provider), # type: ignore[assignment]
):
return await get_authors_games(player, dao.game)
return responses.Page(await get_authors_games(player, dao.game))


async def get_active_game(
Expand All @@ -25,9 +23,9 @@ async def get_active_game(

async def get_all_games(
dao: HolderDao = Depends(dao_provider), # type: ignore[assignment]
) -> Sequence[responses.Game]:
) -> responses.Page[responses.Game]:
games = await get_completed_games(dao.game)
return [responses.Game.from_core(game) for game in games]
return responses.Page([responses.Game.from_core(game) for game in games])


async def get_game_card(
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/api_full/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async def test_games_list(finished_game: dto.FullGame, dao: HolderDao, client: A
resp.read()

dcf = Factory()
actual = dcf.load(resp.json(), list[responses.Game])
assert len(actual) == 1
game = actual[0]
actual: responses.Page[responses.Game] = dcf.load(resp.json(), responses.Page[responses.Game])
assert len(actual.content) == 1
game = actual.content[0]
assert game.id == finished_game.id
assert game.status == GameStatus.complete

Expand Down

0 comments on commit 6f49070

Please sign in to comment.