Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from josuebrunel/integration
Browse files Browse the repository at this point in the history
importing integration in development
  • Loading branch information
josuebrunel committed Jul 18, 2015
2 parents 920e9d8 + 2efeed2 commit f8c1cd9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
27 changes: 23 additions & 4 deletions fantasy_sport/fantasy_sport.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _build_uri(self, resources, keys, sub=None):
if resources:
uri = "{0}={1}".format(resources, self._format_resources_key(keys))
else:
uri = '{0}'.format(self._format_resources_key(keys))
uri = '{0}'.format(self._format_resources_key(keys))

if sub and isinstance(sub, str) :
uri += "/{0}".format(sub)
Expand All @@ -92,15 +92,27 @@ def get_collections(self, resource_type, resource_ids, sub_resources):
#
#################################

def get_games_info(self, game_keys):
def get_games_info(self, game_keys, leagues=None, teams=False, players=None):
"""Return game info
>>> yfs.get_games_info('mlb')
Must set use_login to True to pull teams data
"""
uri = self._build_uri('games;game_keys', game_keys)

if leagues:
uri += '/leagues;league_keys={0}'.format(leagues)

if teams:
uri += '/teams'

if players:
uri += '/players;player_keys={0}'.format(players)

response = self._get(uri)

return response


####################################
#
# LEAGUES
Expand Down Expand Up @@ -150,11 +162,18 @@ def get_leagues_settings(self, league_keys):
response = self._get(uri)
return response

def get_leagues_standings(self, league_keys):
def get_leagues_standings(self, league_keys, teams=None, players=None):
"""Return leagues settings
>>> yfs.get_leagues_settings(['238.l.627062','238.l.627062'])
"""
uri = self._build_uri('leagues;league_keys', league_keys, sub='standings')

if teams:
uri += '/teams/{0}'.format(teams)

if teams=='roster' and players:
uri += '/players/{0}'.format(players)

response = self._get(uri)
return response

Expand Down Expand Up @@ -282,7 +301,7 @@ def get_teams_roster(self, team_keys, week=None, players=None, filters=None):
uri += '/players;{0}'.format(filters)

elif players and not filters:
uri += 'players/{0}'.format(players)
uri += '/players/{0}'.format(players)

response = self._get(uri)
return response
Expand Down
53 changes: 48 additions & 5 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,40 @@
logging.basicConfig(level=logging.DEBUG,format="[%(asctime)s %(levelname)s] [%(name)s.%(module)s.%(funcName)s] %(message)s \n")
logging.getLogger('test-fantasy-sports')

class TestFantasySport(unittest.TestCase):
class TestFantasySportGame(unittest.TestCase):

def setUp(self,):
oauth = OAuth1(None, None, from_file='oauth.json',base_url='http://fantasysports.yahooapis.com/fantasy/v2/')
self.yfs = FantasySport(oauth)

def test_get_games_info(self,):
response = self.yfs.get_games_info(['nfl'])
logging.debug(pretty_json(response.content))
response = self.yfs.get_games_info(['346'])
#response = self.yfs.get_games_info(['nfl'])
#logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

def test_get_games_withleague(self,):
response = self.yfs.get_games_info(['328'], leagues='328.l.56628')
self.assertEqual(response.status_code, 200)
#logging.debug(pretty_json(response.content))

def test_get_games_withplayer(self,):
response = self.yfs.get_games_info(['328'], players='328.p.8180')
self.assertEqual(response.status_code, 200)
#logging.debug(pretty_json(response.content))

def test_get_games_with_login_teams(self,):
self.yfs.use_login = True
response = self.yfs.get_games_info(['346'], teams=True)
self.yfs.use_login = False
self.assertEqual(response.status_code, 200)
#logging.debug(pretty_json(response.content))

def test_get_games_info_with_login(self,):
self.yfs.use_login = True
response = self.yfs.get_games_info(['mlb'])
self.yfs.use_login = False
logging.debug(pretty_json(response.content))
#logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

class TestFantasySportLeague(unittest.TestCase):
Expand Down Expand Up @@ -68,7 +86,12 @@ def test_get_leagues_settings(self):
#logging.debug(pretty_json(response.content))

def test_get_leagues_standings(self):
response = self.yfs.get_leagues_standings(['238.l.627060','238.l.627062'])
response = self.yfs.get_leagues_standings(['346.l.1328'])
self.assertEqual(response.status_code, 200)
#logging.debug(pretty_json(response.content))

def test_get_leagues_standings_withteam_androsterplayers(self):
response = self.yfs.get_leagues_standings(['346.l.1328'], teams='roster', players='ownership')
self.assertEqual(response.status_code, 200)
#logging.debug(pretty_json(response.content))

Expand Down Expand Up @@ -159,6 +182,26 @@ def test_get_teams_roster(self,):
# #logging.debug(pretty_json(response.content))
# self.assertEqual(response.status_code, 200)

def test_get_teams_roster_week(self,):
response = self.yfs.get_teams_roster(['223.l.431.t.9'], week=1)
#logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

def test_get_teams_roster_weekplayer(self,):
response = self.yfs.get_teams_roster(['223.l.431.t.9'], week=1, players='draft_analysis')
#logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

def test_get_teams_roster_players(self,):
response = self.yfs.get_teams_roster(['346.l.1328.t.12'], players='draft_analysis')
#logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

def test_get_teams_roster_filter(self,):
response = self.yfs.get_teams_roster(['346.l.1328.t.12'], filters='position=3B')
#logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

def test_get_teams_draftresults(self,):
response = self.yfs.get_teams_draftresults(['346.l.1328.t.12'])
#logging.debug(pretty_json(response.content))
Expand Down

0 comments on commit f8c1cd9

Please sign in to comment.