Skip to content

Commit

Permalink
cleanup and no enums
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Sep 20, 2024
1 parent 7ed471d commit 49dfaba
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 63 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions sleeper/api/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing import Literal

# TODO: test what is all supported in their apis
Sport = Literal["lcs", "nba", "nfl"]
TrendType = Literal["add", "drop"]
File renamed without changes.
4 changes: 2 additions & 2 deletions sleeper/api/avatar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sleeper.api.constants import AVATARS_ROUTE, SLEEPER_CDN_BASE_URL, THUMBS_ROUTE
from sleeper.api.util import build_route, get_content
from sleeper.api._constants import AVATARS_ROUTE, SLEEPER_CDN_BASE_URL, THUMBS_ROUTE
from sleeper.api._utils import build_route, get_content


def get_avatar(*, avatar_id: str, as_thumbnail: bool = False) -> bytes:
Expand Down
10 changes: 5 additions & 5 deletions sleeper/api/draft.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sleeper.api.constants import (
from sleeper.api._constants import (
DRAFT_ROUTE,
DRAFTS_ROUTE,
LEAGUE_ROUTE,
Expand All @@ -8,8 +8,8 @@
USER_ROUTE,
VERSION,
)
from sleeper.api.util import build_route, get
from sleeper.enum.Sport import Sport
from sleeper.api._types import Sport
from sleeper.api._utils import build_route, get


def get_user_drafts_for_year(*, user_id: str, sport: Sport, year: int) -> list[dict]:
Expand All @@ -19,7 +19,7 @@ def get_user_drafts_for_year(*, user_id: str, sport: Sport, year: int) -> list[d
USER_ROUTE,
user_id,
DRAFTS_ROUTE,
sport.name.lower(),
sport,
year,
)
return get(url)
Expand All @@ -41,7 +41,7 @@ def get_draft(*, draft_id: str) -> dict:
return get(url)


def get_player_draft_picks(*, draft_id: str, sport: Sport) -> list[dict]:
def get_player_draft_picks(*, draft_id: str) -> list[dict]:
url = build_route(
SLEEPER_APP_BASE_URL,
VERSION,
Expand Down
10 changes: 5 additions & 5 deletions sleeper/api/league.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sleeper.api.constants import (
from sleeper.api._constants import (
LEAGUE_ROUTE,
LEAGUES_ROUTE,
LOSERS_BRACKET_ROUTE,
Expand All @@ -13,8 +13,8 @@
VERSION,
WINNERS_BRACKET_ROUTE,
)
from sleeper.api.util import build_route, get
from sleeper.enum import Sport
from sleeper.api._types import Sport
from sleeper.api._utils import build_route, get


def get_league(*, league_id: str) -> dict:
Expand All @@ -29,7 +29,7 @@ def get_user_leagues_for_year(*, user_id: str, sport: Sport, year: int) -> list[
USER_ROUTE,
user_id,
LEAGUES_ROUTE,
sport.value.lower(),
sport,
year,
)
return get(url)
Expand Down Expand Up @@ -115,5 +115,5 @@ def get_traded_picks(*, league_id: str) -> list[dict]:


def get_sport_state(sport: Sport) -> dict:
url = build_route(SLEEPER_APP_BASE_URL, VERSION, STATE_ROUTE, sport.value.lower())
url = build_route(SLEEPER_APP_BASE_URL, VERSION, STATE_ROUTE, sport)
return get(url)
13 changes: 6 additions & 7 deletions sleeper/api/player.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from typing import Optional

from sleeper.api.constants import (
from sleeper.api._constants import (
PLAYERS_ROUTE,
SLEEPER_APP_BASE_URL,
TRENDING_ROUTE,
VERSION,
)
from sleeper.api.util import add_filters, build_route, get
from sleeper.enum.Sport import Sport
from sleeper.enum.TrendType import TrendType
from sleeper.api._types import Sport, TrendType
from sleeper.api._utils import add_filters, build_route, get


def get_all_players(*, sport: Sport) -> dict[str, dict]:
url = build_route(
SLEEPER_APP_BASE_URL,
VERSION,
PLAYERS_ROUTE,
sport.name.lower(),
sport,
)
return get(url)

Expand All @@ -32,9 +31,9 @@ def get_trending_players(
SLEEPER_APP_BASE_URL,
VERSION,
PLAYERS_ROUTE,
sport.name.lower(),
sport,
TRENDING_ROUTE,
trend_type.name.lower(),
trend_type,
)
if lookback_hours is not None:
url = add_filters(url, ("lookback_hours", lookback_hours))
Expand Down
4 changes: 2 additions & 2 deletions sleeper/api/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sleeper.api.constants import SLEEPER_APP_BASE_URL, USER_ROUTE, VERSION
from sleeper.api.util import build_route, get
from sleeper.api._constants import SLEEPER_APP_BASE_URL, USER_ROUTE, VERSION
from sleeper.api._utils import build_route, get


def get_user(*, user_identifier: str) -> dict:
Expand Down
8 changes: 0 additions & 8 deletions sleeper/enum/Sport.py

This file was deleted.

7 changes: 0 additions & 7 deletions sleeper/enum/TrendType.py

This file was deleted.

2 changes: 0 additions & 2 deletions sleeper/enum/__init__.py

This file was deleted.

7 changes: 4 additions & 3 deletions test/integration/test_api/test_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
get_traded_draft_picks,
get_user_drafts_for_year,
)
from sleeper.enum.Sport import Sport
from test.integration.test_api.constants import (
LEAGUE_A_DRAFT_1,
LEAGUE_A_DRAFT_ID_1,
Expand All @@ -24,7 +23,7 @@
class TestDraft(unittest.TestCase):
def test_get_user_drafts_for_year_happy_path(self):
response = get_user_drafts_for_year(
user_id=USER_A_USER_ID, sport=Sport.NFL, year=2023
user_id=USER_A_USER_ID, sport="nfl", year=2023
)
self.assertEqual(USER_A_DRAFTS_2023, response)

Expand All @@ -37,7 +36,9 @@ def test_get_draft(self):
self.assertEqual(LEAGUE_A_DRAFT_1, response)

def test_get_player_draft_picks(self):
response = get_player_draft_picks(draft_id=LEAGUE_A_DRAFT_ID_1, sport=Sport.NFL)
response = get_player_draft_picks(
draft_id=LEAGUE_A_DRAFT_ID_1,
)
self.assertEqual(USER_A_DRAFT_PICKS_DRAFT_ID_1_2023, response)

def test_get_traded_draft_picks(self):
Expand Down
5 changes: 2 additions & 3 deletions test/integration/test_api/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
get_users_in_league,
get_winners_bracket,
)
from sleeper.enum import Sport
from test.integration.test_api.constants import (
LEAGUE_A_LEAGUE,
LEAGUE_A_LEAGUE_ID,
Expand All @@ -36,7 +35,7 @@ def test_get_league(self):

def test_get_user_leagues_for_year(self):
response = get_user_leagues_for_year(
user_id=USER_A_USER_ID, sport=Sport.NFL, year=2022
user_id=USER_A_USER_ID, sport="nfl", year=2022
)
self.assertEqual(USER_A_LEAGUES_2022, response)

Expand Down Expand Up @@ -73,7 +72,7 @@ def test_get_traded_picks(self):
self.assertEqual(LEAGUE_C_TRADED_PICKS, response)

def test_get_sport_state(self):
response = get_sport_state(sport=Sport.NFL)
response = get_sport_state(sport="nfl")
# this response will constantly change, so just assert some general things
self.assertIsInstance(response, dict)
for k in response.keys():
Expand Down
6 changes: 2 additions & 4 deletions test/integration/test_api/test_player.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import unittest

from sleeper.api.player import get_all_players, get_trending_players
from sleeper.enum.Sport import Sport
from sleeper.enum.TrendType import TrendType


class TestPlayer(unittest.TestCase):
def test_get_all_players(self):
response = get_all_players(sport=Sport.NFL)
response = get_all_players(sport="nfl")
# this response will constantly change, so just assert some general things
self.assertIsInstance(response, dict)
for k, v in response.items():
self.assertIsInstance(k, str)
self.assertIsInstance(v, dict)

def test_get_trending_players(self):
response = get_trending_players(sport=Sport.NFL, trend_type=TrendType.ADD)
response = get_trending_players(sport="nfl", trend_type="add")
# this response will constantly change, so just assert some general things
self.assertIsInstance(response, list)
self.assertEqual(25, len(response))
Expand Down
7 changes: 2 additions & 5 deletions test/unit/test_api/test_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
get_traded_draft_picks,
get_user_drafts_for_year,
)
from sleeper.enum.Sport import Sport
from test.unit.helper.helper_classes import MockResponse


Expand All @@ -19,9 +18,7 @@ def test_get_user_drafts_for_year_happy_path(self, mock_requests_get):
mock_response = MockResponse(mock_list, 200)
mock_requests_get.return_value = mock_response

response = get_user_drafts_for_year(
user_id="user_id", sport=Sport.NFL, year=2020
)
response = get_user_drafts_for_year(user_id="user_id", sport="nfl", year=2020)

self.assertEqual(mock_list, response)
mock_requests_get.assert_called_once_with(
Expand Down Expand Up @@ -60,7 +57,7 @@ def test_get_player_draft_picks(self, mock_requests_get):
mock_response = MockResponse(mock_dict, 200)
mock_requests_get.return_value = mock_response

response = get_player_draft_picks(draft_id="12345", sport=Sport.NFL)
response = get_player_draft_picks(draft_id="12345")

self.assertEqual(mock_dict, response)
mock_requests_get.assert_called_once_with(
Expand Down
7 changes: 2 additions & 5 deletions test/unit/test_api/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
get_users_in_league,
get_winners_bracket,
)
from sleeper.enum import Sport
from test.unit.helper.helper_classes import MockResponse


Expand All @@ -37,9 +36,7 @@ def test_get_user_leagues_for_year(self, mock_requests_get):
mock_response = MockResponse(mock_list, 200)
mock_requests_get.return_value = mock_response

response = get_user_leagues_for_year(
user_id="12345", sport=Sport.NFL, year=2024
)
response = get_user_leagues_for_year(user_id="12345", sport="nfl", year=2024)

self.assertEqual(mock_list, response)
mock_requests_get.assert_called_once_with(
Expand Down Expand Up @@ -143,7 +140,7 @@ def test_get_sport_state(self, mock_requests_get):
mock_response = MockResponse(mock_dict, 200)
mock_requests_get.return_value = mock_response

response = get_sport_state(sport=Sport.NFL)
response = get_sport_state(sport="nfl")

self.assertEqual(mock_dict, response)
mock_requests_get.assert_called_once_with(
Expand Down
8 changes: 3 additions & 5 deletions test/unit/test_api/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from unittest.mock import patch

from sleeper.api.player import get_all_players, get_trending_players
from sleeper.enum.Sport import Sport
from sleeper.enum.TrendType import TrendType
from test.unit.helper.helper_classes import MockResponse


Expand All @@ -14,7 +12,7 @@ def test_get_all_players(self, mock_requests_get):
mock_response = MockResponse(mock_dict, 200)
mock_requests_get.return_value = mock_response

response = get_all_players(sport=Sport.NFL)
response = get_all_players(sport="nfl")

self.assertEqual(mock_dict, response)
mock_requests_get.assert_called_once_with(
Expand All @@ -27,7 +25,7 @@ def test_get_trending_players_with_defaults(self, mock_requests_get):
mock_response = MockResponse(mock_list, 200)
mock_requests_get.return_value = mock_response

response = get_trending_players(sport=Sport.NFL, trend_type=TrendType.ADD)
response = get_trending_players(sport="nfl", trend_type="add")

self.assertEqual(mock_list, response)
mock_requests_get.assert_called_once_with(
Expand All @@ -41,7 +39,7 @@ def test_get_trending_players_with_optional_params_given(self, mock_requests_get
mock_requests_get.return_value = mock_response

response = get_trending_players(
sport=Sport.NFL, trend_type=TrendType.ADD, lookback_hours=1, limit=2
sport="nfl", trend_type="add", lookback_hours=1, limit=2
)

self.assertEqual(mock_list, response)
Expand Down

0 comments on commit 49dfaba

Please sign in to comment.