From 777881320635142131b196e564840d950b051b51 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Sun, 11 Aug 2024 21:52:36 +0200 Subject: [PATCH] Wrote basic number statistic retrieval pytest --- src/classes/statistic_classes.py | 4 ++-- src/main.py | 6 +++--- tests/test_main.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/classes/statistic_classes.py b/src/classes/statistic_classes.py index ed9680c..89f974a 100644 --- a/src/classes/statistic_classes.py +++ b/src/classes/statistic_classes.py @@ -1,5 +1,5 @@ from pydantic import BaseModel -class BaseIntStatistic(BaseModel): +class BaseNumberStatistic(BaseModel): name: str - result: int \ No newline at end of file + result: float \ No newline at end of file diff --git a/src/main.py b/src/main.py index 238d5ab..86d980b 100644 --- a/src/main.py +++ b/src/main.py @@ -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 \ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py index b89730d..15af72c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file