diff --git a/setup.py b/setup.py index 5b591ce..8ea83a5 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def readme(): setup(name='yahoo_fantasy_api', - version='2.10.0', + version='2.10.1', description='Python bindings to access the Yahoo! Fantasy APIs', long_description=readme(), url='http://github.com/spilchen/yahoo_fantasy_api', diff --git a/yahoo_fantasy_api/game.py b/yahoo_fantasy_api/game.py index f46044d..c6f35f4 100644 --- a/yahoo_fantasy_api/game.py +++ b/yahoo_fantasy_api/game.py @@ -41,8 +41,7 @@ def to_league(self, league_id): :return: Fully constructed object :rtype: League """ - lg = league.League(self.sc, league_id) - lg.inject_yhandler(self.yhandler) + lg = league.League(self.sc, league_id, handler=self.yhandler) return lg def league_ids(self, year=None): diff --git a/yahoo_fantasy_api/league.py b/yahoo_fantasy_api/league.py index 2792704..e8549e1 100644 --- a/yahoo_fantasy_api/league.py +++ b/yahoo_fantasy_api/league.py @@ -17,10 +17,13 @@ class League: :type league_id: str """ - def __init__(self, sc, league_id): + def __init__(self, sc, league_id, handler=None): self.sc = sc self.league_id = league_id - self.yhandler = yhandler.YHandler(sc) + if handler: + self.yhandler = handler + else: + self.yhandler = yhandler.YHandler(sc) self.current_week_cache = None self.end_week_cache = None self.week_date_range_cache = {} @@ -33,6 +36,9 @@ def __init__(self, sc, league_id): self.positions_cache = None self.stats_id_map = None self.player_details_cache = {} + lg_settings = self.settings() + game_code = lg_settings['game_code'] + self._cache_stats_id_map(game_code) def inject_yhandler(self, yhandler): self.yhandler = yhandler diff --git a/yahoo_fantasy_api/tests/conftest.py b/yahoo_fantasy_api/tests/conftest.py index 465ae64..5e3db46 100644 --- a/yahoo_fantasy_api/tests/conftest.py +++ b/yahoo_fantasy_api/tests/conftest.py @@ -14,22 +14,19 @@ def sc(): @pytest.fixture() def mock_mlb_league(sc): - lg = yfa.League(sc, '370.l.56877') - lg.inject_yhandler(mock_yhandler.YHandler()) + lg = yfa.League(sc, '370.l.56877', handler=mock_yhandler.YHandler()) yield lg @pytest.fixture() def mock_nhl_league(sc): - lg = yfa.League(sc, '396.l.21484') - lg.inject_yhandler(mock_yhandler.YHandler()) + lg = yfa.League(sc, '396.l.21484', handler=mock_yhandler.YHandler()) yield lg @pytest.fixture() def mock_nfl_league(sc): - lg = yfa.League(sc, '449.l.75178') - lg.inject_yhandler(mock_yhandler.YHandler()) + lg = yfa.League(sc, '449.l.75178', handler=mock_yhandler.YHandler()) yield lg