Skip to content

Commit

Permalink
Adding ouath decorator to get_player_details and updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DMcP89 committed Aug 29, 2024
1 parent 14d3a2e commit e6e39cf
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions harambot/yahoo_api.py
Original file line number Diff line number Diff line change
@@ -158,6 +158,7 @@ def get_roster(self, team_name, guild_id):
return None

@cached(cache)
@handle_oauth
def get_player_details(self, player_name, guild_id):
try:
player = self.league().player_details(player_name)[0]
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ def api(
mock_ownership,
mock_matchups,
):
api = Yahoo(mock_oauth, "123456", "nfl")
api = Yahoo()
api.scoring_type = "head"
league = None
with patch.object(game.Game, "game_id", return_value="319"):
@@ -94,7 +94,7 @@ def category_api(
mock_ownership,
mock_matchups_category,
):
api = Yahoo(mock_oauth, "123456", "nfl")
api = Yahoo()
api.scoring_type = "headone"
league = None
with patch.object(game.Game, "game_id", return_value="319"):
25 changes: 20 additions & 5 deletions tests/test_yahoo_api.py
Original file line number Diff line number Diff line change
@@ -7,15 +7,21 @@ def test_league(api):


def test_get_standings(api):
return_value = api.get_standings()
get_standings_func = api.get_standings
while hasattr(get_standings_func, "__wrapped__"):
get_standings_func = get_standings_func.__wrapped__
return_value = get_standings_func(api, "mock")
assert isinstance(return_value, list)
assert len(return_value) == 3
assert return_value[0]["place"] == "1. Hide and Go Zeke"


def test_get_roster(api, mock_roster):
get_roster_func = api.get_roster
while hasattr(get_roster_func, "__wrapped__"):
get_roster_func = get_roster_func.__wrapped__
with patch.object(team.Team, "roster", return_value=mock_roster):
return_value = api.get_roster("Too Many Cooks")
return_value = get_roster_func(api, "Too Many Cooks", guild_id="mock")
assert isinstance(return_value, list)
assert return_value[0]["selected_position"] == "QB"
assert return_value[0]["name"] == "Josh Allen"
@@ -28,20 +34,29 @@ def test_get_player_owner(api):


def test_get_player_details(api):
return_value = api.get_player_details("Josh Allen")
get_player_details_func = api.get_player_details
while hasattr(get_player_details_func, "__wrapped__"):
get_player_details_func = get_player_details_func.__wrapped__
return_value = get_player_details_func(api, "Josh Allen", guild_id="mock")
assert isinstance(return_value, dict)
assert return_value["player_key"] == "399.p.30977"
assert return_value["owner"] == "Hide and Go Zeke"


def test_get_matchups(api):
week, details = api.get_matchups()
get_matchups_func = api.get_matchups
while hasattr(get_matchups_func, "__wrapped__"):
get_matchups_func = get_matchups_func.__wrapped__
week, details = get_matchups_func(api, guild_id="mock")
assert isinstance(details, list)
assert week == "1"


def test_get_matchups_category(category_api):
week, details = category_api.get_matchups()
get_matchups_func = category_api.get_matchups
while hasattr(get_matchups_func, "__wrapped__"):
get_matchups_func = get_matchups_func.__wrapped__
week, details = get_matchups_func(category_api, guild_id="mock")
assert isinstance(details, list)
assert len(details) == 7
assert week == "1"

0 comments on commit e6e39cf

Please sign in to comment.