Wrote more pytests
This commit is contained in:
parent
b0826b875c
commit
746f7fb4a7
2 changed files with 50 additions and 8 deletions
|
|
@ -16,6 +16,13 @@ class GameOrderStatistic(StatisticBase):
|
|||
boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion,
|
||||
boardgame_classes.WishlistBoardGame, boardgame_classes.WishlistBoardGameExpansion]]
|
||||
|
||||
model_config = {
|
||||
'validate_assignment':True
|
||||
}
|
||||
|
||||
class TimeLineStatistic(StatisticBase):
|
||||
result: Dict[date, int]
|
||||
|
||||
model_config = {
|
||||
'validate_assignment':True
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import validators
|
||||
from fastapi.testclient import TestClient
|
||||
from datetime import date
|
||||
from typing import Union
|
||||
from typing import Union, Dict
|
||||
|
||||
from src.main import app
|
||||
|
||||
|
|
@ -25,6 +25,9 @@ def default_boardgame_test(to_test_boardgame: boardgame_classes.BoardGame):
|
|||
assert type(to_test_boardgame.type) == boardgame_classes.BoardgameType
|
||||
|
||||
|
||||
def default_statistic_test(to_test_statistic: statistic_classes.StatisticBase):
|
||||
assert type(to_test_statistic.name) == str, to_test_statistic
|
||||
|
||||
|
||||
def test_read_main():
|
||||
response = client.get("/")
|
||||
|
|
@ -35,7 +38,7 @@ def test_retrieve_boardgame():
|
|||
response = client.get("/boardgame?id=373167")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_boardgame = boardgame_classes.BoardGame(**response.json())
|
||||
returned_boardgame = boardgame_classes.BoardGame.model_validate(response.json())
|
||||
|
||||
default_boardgame_test(returned_boardgame)
|
||||
|
||||
|
|
@ -43,7 +46,7 @@ def test_retrieve_owned():
|
|||
response = client.get("/owned")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_boardgame = boardgame_classes.OwnedBoardGame(**response.json()[0])
|
||||
returned_boardgame = boardgame_classes.OwnedBoardGame.model_validate(response.json()[0])
|
||||
|
||||
default_boardgame_test(returned_boardgame)
|
||||
assert type(returned_boardgame.price_paid) == float
|
||||
|
|
@ -55,7 +58,7 @@ def test_retrieve_wishlist():
|
|||
response = client.get("/wishlist")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_boardgame = boardgame_classes.WishlistBoardGame(**response.json()[0])
|
||||
returned_boardgame = boardgame_classes.WishlistBoardGame.model_validate(response.json()[0])
|
||||
|
||||
default_boardgame_test(returned_boardgame)
|
||||
assert type(returned_boardgame.wishlist_priority) == int
|
||||
|
|
@ -91,7 +94,39 @@ def test_retrieve_basic_statistic():
|
|||
response = client.get("/statistics/amount_of_games")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_statistic = statistic_classes.NumberStatistic(**response.json())
|
||||
returned_statistic = statistic_classes.NumberStatistic.model_validate(response.json())
|
||||
|
||||
assert type(returned_statistic.name) == str
|
||||
default_statistic_test(returned_statistic)
|
||||
assert type(returned_statistic.result) == float
|
||||
|
||||
|
||||
def test_retrieve_timeline_statistic():
|
||||
response = client.get("/statistics/amount_of_games_over_time")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_statistic = statistic_classes.TimeLineStatistic.model_validate(response.json())
|
||||
|
||||
default_statistic_test(returned_statistic)
|
||||
assert type(returned_statistic.result) == dict
|
||||
|
||||
response = client.get("/statistics/games_played_per_year")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_statistic = statistic_classes.TimeLineStatistic.model_validate(response.json())
|
||||
|
||||
default_statistic_test(returned_statistic)
|
||||
assert type(returned_statistic.result) == dict
|
||||
|
||||
|
||||
def test_retrieve_game_order_statistic():
|
||||
response = client.get("/statistics/most_expensive_games")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_statistic = statistic_classes.GameOrderStatistic.model_validate(response.json())
|
||||
|
||||
default_statistic_test(returned_statistic)
|
||||
assert type(returned_statistic.result) == list
|
||||
assert type(returned_statistic.result[0]) in [
|
||||
boardgame_classes.BoardGame, boardgame_classes.BoardGameExpansion,
|
||||
boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion,
|
||||
boardgame_classes.WishlistBoardGame, boardgame_classes.WishlistBoardGameExpansion]
|
||||
Loading…
Reference in a new issue