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
|
from pydantic import BaseModel
|
||||||
|
|
||||||
class BaseIntStatistic(BaseModel):
|
class BaseNumberStatistic(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
result: int
|
result: float
|
||||||
|
|
@ -64,7 +64,7 @@ def get_players_from_play(play_id):
|
||||||
return requested_players
|
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():
|
def get_amount_of_games():
|
||||||
|
|
||||||
statistic_dict = {
|
statistic_dict = {
|
||||||
|
|
@ -72,6 +72,6 @@ def get_amount_of_games():
|
||||||
"result":len(data_connection.get_user_owned_collection())
|
"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
|
return statistic_to_return
|
||||||
|
|
@ -5,7 +5,7 @@ from typing import Union
|
||||||
|
|
||||||
from src.main import app
|
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)
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|
@ -86,3 +86,12 @@ def test_retrieve_players():
|
||||||
assert type(returned_player.first_play) == bool
|
assert type(returned_player.first_play) == bool
|
||||||
assert type(returned_player.has_won) == 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