Wrote basic number statistic retrieval pytest
This commit is contained in:
parent
fa9fe046a9
commit
7778813206
3 changed files with 16 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
class BaseIntStatistic(BaseModel):
|
||||
class BaseNumberStatistic(BaseModel):
|
||||
name: str
|
||||
result: int
|
||||
result: float
|
||||
|
|
@ -64,7 +64,7 @@ def get_players_from_play(play_id):
|
|||
return requested_players
|
||||
|
||||
|
||||
@app.get('/statistics/amount_of_games', response_model=statistic_classes.BaseIntStatistic)
|
||||
@app.get('/statistics/amount_of_games', response_model=statistic_classes.BaseNumberStatistic)
|
||||
def get_amount_of_games():
|
||||
|
||||
statistic_dict = {
|
||||
|
|
@ -72,6 +72,6 @@ def get_amount_of_games():
|
|||
"result":len(data_connection.get_user_owned_collection())
|
||||
}
|
||||
|
||||
statistic_to_return = statistic_classes.BaseIntStatistic(**statistic_dict)
|
||||
|
||||
statistic_to_return = statistic_classes.BaseNumberStatistic(**statistic_dict)
|
||||
|
||||
return statistic_to_return
|
||||
|
|
@ -5,7 +5,7 @@ from typing import Union
|
|||
|
||||
from src.main import app
|
||||
|
||||
from src.classes import boardgame_classes, play_classes
|
||||
from src.classes import boardgame_classes, play_classes, statistic_classes
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
|
@ -85,4 +85,13 @@ def test_retrieve_players():
|
|||
assert type(returned_player.score) == float or returned_player.score == None
|
||||
assert type(returned_player.first_play) == bool
|
||||
assert type(returned_player.has_won) == bool
|
||||
assert type(returned_player.play_id) == int
|
||||
assert type(returned_player.play_id) == int
|
||||
|
||||
def test_retrieve_basic_statistic():
|
||||
response = client.get("/statistics/amount_of_games")
|
||||
assert response.status_code == 200
|
||||
|
||||
returned_statistic = statistic_classes.BaseNumberStatistic(**response.json())
|
||||
|
||||
assert type(returned_statistic.name) == str
|
||||
assert type(returned_statistic.result) == float
|
||||
Loading…
Reference in a new issue