Skip to content

Commit

Permalink
another func with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Sep 20, 2024
1 parent 90c0462 commit 7ed471d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sleeper/api/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MATCHUPS_ROUTE,
ROSTERS_ROUTE,
SLEEPER_APP_BASE_URL,
STATE_ROUTE,
TRADED_PICKS_ROUTE,
TRANSACTIONS_ROUTE,
USER_ROUTE,
Expand Down Expand Up @@ -111,3 +112,8 @@ def get_traded_picks(*, league_id: str) -> list[dict]:
TRADED_PICKS_ROUTE,
)
return get(url)


def get_sport_state(sport: Sport) -> dict:
url = build_route(SLEEPER_APP_BASE_URL, VERSION, STATE_ROUTE, sport.value.lower())
return get(url)
8 changes: 8 additions & 0 deletions test/integration/test_api/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
get_losers_bracket,
get_matchups_for_week,
get_rosters,
get_sport_state,
get_traded_picks,
get_transactions,
get_user_leagues_for_year,
Expand Down Expand Up @@ -70,3 +71,10 @@ def test_get_transactions(self):
def test_get_traded_picks(self):
response = get_traded_picks(league_id=LEAGUE_C_LEAGUE_ID)
self.assertEqual(LEAGUE_C_TRADED_PICKS, response)

def test_get_sport_state(self):
response = get_sport_state(sport=Sport.NFL)
# this response will constantly change, so just assert some general things
self.assertIsInstance(response, dict)
for k in response.keys():
self.assertIsInstance(k, str)
14 changes: 14 additions & 0 deletions test/unit/test_api/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get_losers_bracket,
get_matchups_for_week,
get_rosters,
get_sport_state,
get_traded_picks,
get_transactions,
get_user_leagues_for_year,
Expand Down Expand Up @@ -135,3 +136,16 @@ def test_get_traded_picks(self, mock_requests_get):
mock_requests_get.assert_called_once_with(
"https://api.sleeper.app/v1/league/12345/traded_picks"
)

@patch("requests.get")
def test_get_sport_state(self, mock_requests_get):
mock_dict = {"foo": "bar"}
mock_response = MockResponse(mock_dict, 200)
mock_requests_get.return_value = mock_response

response = get_sport_state(sport=Sport.NFL)

self.assertEqual(mock_dict, response)
mock_requests_get.assert_called_once_with(
"https://api.sleeper.app/v1/state/nfl"
)

0 comments on commit 7ed471d

Please sign in to comment.