Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeall committed Dec 14, 2023
1 parent 206962a commit 1d507de
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/players/test_players_injuries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from datetime import datetime

import pytest
from fastapi import HTTPException
from schema import And, Optional, Schema

from app.services.players.injuries import TransfermarktPlayerInjuries


def test_get_player_market_value_not_found():
with pytest.raises(HTTPException):
TransfermarktPlayerInjuries(player_id="0")


@pytest.mark.parametrize(
"player_id,page_number", [("28003", 1), ("28003", 2), ("28003", 3), ("28003", 999), ("8198", 1), ("8198", 999)],
)
def test_get_player_injuries(player_id, page_number, len_greater_than_0, regex_integer, regex_date_mmm_dd_yyyy):
tfmkt = TransfermarktPlayerInjuries(player_id=player_id, page_number=page_number)
result = tfmkt.get_player_injuries()

expected_schema = Schema(
{
"id": And(str, regex_integer),
"pageNumber": int,
"lastPageNumber": int,
"injuries": [
{
"season": And(str, len_greater_than_0),
"injury": And(str, len_greater_than_0),
"from": And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
"until": And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
"days": And(str, len_greater_than_0),
Optional("gamesMissed"): And(str, len_greater_than_0, regex_integer),
Optional("gamesMissedClubs"): list[str],
},
],
"updatedAt": datetime,
},
)

assert expected_schema.validate(result)

0 comments on commit 1d507de

Please sign in to comment.