Skip to content

Commit

Permalink
added func
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Aug 30, 2024
1 parent 742d6d8 commit 1b4b0fb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sleeper/api/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
LEAGUE_ROUTE,
PICKS_ROUTE,
SLEEPER_APP_BASE_URL,
TRADED_PICKS_ROUTE,
USER_ROUTE,
VERSION,
)
Expand Down Expand Up @@ -65,3 +66,17 @@ def get_player_draft_picks(*, draft_id: str, sport: Sport) -> list[dict]:
f"Could not get PlayerDraftPicks with draft_id '{draft_id}' and sport '{sport.name}'."
)
return response_list


def get_traded_draft_picks(*, draft_id: str) -> list[dict]:
url = build_route(
SLEEPER_APP_BASE_URL,
VERSION,
DRAFT_ROUTE,
draft_id,
TRADED_PICKS_ROUTE,
)
response_list = get(url)
if response_list is None:
raise ValueError(f"Could not get traded DraftPicks with draft_id '{draft_id}'.")
return response_list
43 changes: 43 additions & 0 deletions test/integration/test_api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,46 @@
}
]
LEAGUE_A_DRAFT_ID_1 = "874771855859945472"
LEAGUE_A_DRAFT_ID_2 = "1121675041713864705"
LEAGUE_A_DRAFT_ID_2_TRADED_PICKS = [
{
"round": 8,
"season": "2024",
"draft_id": 1121675041713864705,
"roster_id": 1,
"owner_id": 4,
"previous_owner_id": 1,
},
{
"round": 5,
"season": "2024",
"draft_id": 1121675041713864705,
"roster_id": 2,
"owner_id": 1,
"previous_owner_id": 2,
},
{
"round": 2,
"season": "2024",
"draft_id": 1121675041713864705,
"roster_id": 5,
"owner_id": 3,
"previous_owner_id": 5,
},
{
"round": 5,
"season": "2024",
"draft_id": 1121675041713864705,
"roster_id": 5,
"owner_id": 2,
"previous_owner_id": 5,
},
{
"round": 2,
"season": "2024",
"draft_id": 1121675041713864705,
"roster_id": 6,
"owner_id": 3,
"previous_owner_id": 6,
},
]
7 changes: 7 additions & 0 deletions test/integration/test_api/test_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
get_draft,
get_drafts_in_league,
get_player_draft_picks,
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,
LEAGUE_A_DRAFT_ID_2,
LEAGUE_A_DRAFT_ID_2_TRADED_PICKS,
LEAGUE_A_DRAFTS,
LEAGUE_A_LEAGUE_ID_1,
USER_A_DRAFT_PICKS_DRAFT_ID_1_2023,
Expand All @@ -36,3 +39,7 @@ def test_get_draft(self):
def test_get_player_draft_picks(self):
response = get_player_draft_picks(draft_id=LEAGUE_A_DRAFT_ID_1, sport=Sport.NFL)
self.assertEqual(USER_A_DRAFT_PICKS_DRAFT_ID_1_2023, response)

def test_get_traded_draft_picks(self):
response = get_traded_draft_picks(draft_id=LEAGUE_A_DRAFT_ID_2)
self.assertEqual(LEAGUE_A_DRAFT_ID_2_TRADED_PICKS, response)
14 changes: 14 additions & 0 deletions test/unit/test_api/test_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
get_draft,
get_drafts_in_league,
get_player_draft_picks,
get_traded_draft_picks,
get_user_drafts_for_year,
)
from sleeper.enum.Sport import Sport
Expand Down Expand Up @@ -64,3 +65,16 @@ def test_get_player_draft_picks(self, mock_requests_get):
mock_requests_get.assert_called_once_with(
"https://api.sleeper.app/v1/draft/12345/picks"
)

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

response = get_traded_draft_picks(draft_id="12345")

self.assertEqual(mock_dict, response)
mock_requests_get.assert_called_once_with(
"https://api.sleeper.app/v1/draft/12345/traded_picks"
)

0 comments on commit 1b4b0fb

Please sign in to comment.