Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mlbstatsapi/models/awards/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class Award(MLBBaseModel):
Date of when award was given.
season : str
Season award is for/from.
team : Team
Team award was to / Player is from.
team : Team, optional
Team award was to / Player is from. None when MLB sends no
team, e.g. Hall of Fame executives and pioneers.
player : Person
Person award is for.
votes : int
Expand All @@ -31,7 +32,7 @@ class Award(MLBBaseModel):
name: str
date: str
season: str
team: Team
team: Optional[Team] = None
player: Person
votes: Optional[int] = None
notes: Optional[str] = None
17 changes: 17 additions & 0 deletions tests/parsers/test_awards_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ def test_parse_awards():

assert awards == [Award(**AWARD_PAYLOAD)]
assert awards[0].player.full_name == "Aaron Judge"


def test_parse_awards_without_team():
"""Recipients such as Hall of Fame executives come back without a team."""
payload = {
"id": "MLBHOF",
"name": "Hall Of Fame",
"date": "2021-12-05",
"season": "2021",
"player": {"id": 650067, "link": "/api/v1/people/650067", "nameFirstLast": "Buck O'Neil"},
}

awards = parse_awards({"awards": [AWARD_PAYLOAD, payload]})

assert len(awards) == 2
assert awards[1].team is None
assert awards[1].player.id == 650067
Loading