Skip to content

Commit

Permalink
Merge pull request #9 from joeyagreco/playoff-round-type
Browse files Browse the repository at this point in the history
Added PlayoffRoundType enum field
  • Loading branch information
joeyagreco authored Sep 7, 2022
2 parents f5f5545 + 937c193 commit 70e86da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sleeper/enum/PlayoffRoundType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from enum import unique

from sleeper.enum.ModelEnum import ModelEnum


@unique
class PlayoffRoundType(ModelEnum):
ONE_WEEK_PER_ROUND = "ONE_WEEK_PER_ROUND" # each round of playoffs is one week
TWO_WEEK_CHAMPIONSHIP_ROUND = "TWO_WEEK_CHAMPIONSHIP_ROUND" # each round of playoffs is one week, while the championship spans two weeks
TWO_WEEKS_PER_ROUND = "TWO_WEEKS_PER_ROUND" # each round of playoffs spans two weeks

@classmethod
def from_int(cls, val: int) -> PlayoffRoundType:
if val == 0:
return PlayoffRoundType.ONE_WEEK_PER_ROUND
elif val == 1:
return PlayoffRoundType.TWO_WEEK_CHAMPIONSHIP_ROUND
elif val == 2:
return PlayoffRoundType.TWO_WEEKS_PER_ROUND
else:
cls._handle_unknown_value(PlayoffRoundType, str(val))
5 changes: 5 additions & 0 deletions sleeper/model/LeagueSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from dataclasses import dataclass

from sleeper.enum.PlayoffRoundType import PlayoffRoundType


@dataclass(kw_only=True)
class LeagueSettings:
Expand All @@ -25,6 +27,7 @@ class LeagueSettings:
offseason_adds: int
pick_trading: int
playoff_round_type: int
playoff_round_type_enum: PlayoffRoundType # a more clear representation of the "playoff_round_type" field
playoff_seed_type: int
playoff_teams: int
playoff_type: int
Expand Down Expand Up @@ -82,6 +85,8 @@ def from_dict(settings_dict: dict) -> LeagueSettings:
disable_trades=settings_dict.get("disable_trades"),
league_average_match=settings_dict.get("league_average_match"),
playoff_round_type=settings_dict.get("playoff_round_type"),
playoff_round_type_enum=PlayoffRoundType.from_int(
settings_dict.get("playoff_round_type")),
playoff_seed_type=settings_dict.get("playoff_seed_type"),
playoff_type=settings_dict.get("playoff_type"),
reserve_allow_cov=settings_dict.get("reserve_allow_cov"),
Expand Down
3 changes: 3 additions & 0 deletions test/test_api/test_LeagueAPIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from requests import HTTPError

from sleeper.api import LeagueAPIClient
from sleeper.enum.PlayoffRoundType import PlayoffRoundType
from sleeper.enum.SeasonStatus import SeasonStatus
from sleeper.enum.SeasonType import SeasonType
from sleeper.enum.Sport import Sport
Expand Down Expand Up @@ -368,6 +369,7 @@ def test_get_league_happy_path(self, mock_requests_get):
self.assertEqual(1, response.settings.disable_trades)
self.assertEqual(0, response.settings.league_average_match)
self.assertEqual(0, response.settings.playoff_round_type)
self.assertEqual(PlayoffRoundType.ONE_WEEK_PER_ROUND, response.settings.playoff_round_type_enum)
self.assertEqual(0, response.settings.playoff_seed_type)
self.assertEqual(0, response.settings.playoff_type)
self.assertEqual(0, response.settings.reserve_allow_cov)
Expand Down Expand Up @@ -742,6 +744,7 @@ def test_get_user_leagues_for_year_happy_path(self, mock_requests_get):
self.assertEqual(1, response.settings.disable_trades)
self.assertEqual(0, response.settings.league_average_match)
self.assertEqual(0, response.settings.playoff_round_type)
self.assertEqual(PlayoffRoundType.ONE_WEEK_PER_ROUND, response.settings.playoff_round_type_enum)
self.assertEqual(0, response.settings.playoff_seed_type)
self.assertEqual(0, response.settings.playoff_type)
self.assertEqual(0, response.settings.reserve_allow_cov)
Expand Down

0 comments on commit 70e86da

Please sign in to comment.