def testParseTeamInfo_fullTeamInfoExists(self): """Don't update db with FullTeamInfo if it already exist.""" id = 'njcj4s6Ct8EmLJyC98tkMEP3YQC5QiKs33MnNEu9jp0%3d' key = game_model.full_team_info_key(id) team_info = score_reporter_crawler.TeamInfo() team_info.facebook_url = 'https://www.facebook.com/TexasUltimate' team_info.name = 'Texas (TUFF)' team_info.website = 'http://texasultimate.wix.com/texasultimate' team_info.id = id team_info.twitter_screenname = 'texasultimate' info_pb = game_model.FullTeamInfo.FromTeamInfo(team_info, scores_messages.Division.OPEN, scores_messages.AgeBracket.COLLEGE, key=key) info_pb.put() self._runParseTeamTest()
def _runParseTeamTest(self, twitter_id=None): self.SetHtmlResponse(FAKE_TEAM_INFO_PAGE) params = { 'id': 'g%3d', 'division': 'OPEN', 'age_bracket': 'COLLEGE', } response = self.testapp.get('/tasks/sr/crawl_team', params=params) self.assertEqual(200, response.status_int) id = 'njcj4s6Ct8EmLJyC98tkMEP3YQC5QiKs33MnNEu9jp0%3d' # 1. Check the Team info in the datastore query = game_model.Team.query() teams = query.fetch(1000) self.assertEqual(1, len(teams)) # Full team ID as crawled from FAKE_TEAM_INFO_PAGE. self.assertEqual(id, teams[0].score_reporter_id) self.assertEqual(twitter_id, teams[0].twitter_id) # 2. Check the FullTeamInfo in the datastore query = game_model.FullTeamInfo.query() teams = query.fetch(1000) self.assertEqual(1, len(teams)) key = game_model.full_team_info_key(id) self.assertEqual( 'https://www.facebook.com/TexasUltimate', teams[0].facebook_url) self.assertEqual( scores_messages.AgeBracket.COLLEGE, teams[0].age_bracket) self.assertEqual( scores_messages.Division.OPEN, teams[0].division) self.assertEqual('Texas (TUFF)', teams[0].name) self.assertEqual('texasultimate', teams[0].screen_name) self.assertEqual( 'http://texasultimate.wix.com/texasultimate', teams[0].website) self.assertEqual( id, teams[0].id) # 3. Check the TeamIdLookup in the datastore query = game_model.TeamIdLookup.query() items = query.fetch(1000) self.assertEqual(1, len(items)) self.assertEqual(id, items[0].score_reporter_id) self.assertEqual(1, len(items[0].score_reporter_tourney_id)) self.assertEqual('g%3d', items[0].score_reporter_tourney_id[0])
def testParseTeamInfo_fullTeamInfoExists(self): """Don't update db with FullTeamInfo if it already exist.""" id = 'njcj4s6Ct8EmLJyC98tkMEP3YQC5QiKs33MnNEu9jp0%3d' key = game_model.full_team_info_key(id) team_info = score_reporter_crawler.TeamInfo() team_info.facebook_url = 'https://www.facebook.com/TexasUltimate' team_info.name = 'Texas (TUFF)' team_info.website = 'http://texasultimate.wix.com/texasultimate' team_info.id = id team_info.twitter_screenname = 'texasultimate' info_pb = game_model.FullTeamInfo.FromTeamInfo( team_info, scores_messages.Division.OPEN, scores_messages.AgeBracket.COLLEGE, key=key) info_pb.put() self._runParseTeamTest()
def _PossiblyStoreFullTeamInfo(self, team_info, division, age_bracket): """If we don't know about this team, update the FullTeamInfo. Args: team_info: score_reporter_crawler.TeamInfo object division: scores_messages.Division division of team age_bracket: scores_messages.AgeBracket age bracket of team """ key = game_model.full_team_info_key(team_info.id) info_pb = key.get() if info_pb: # TODO(P2): check to see if fields have changed and update. return info_pb = game_model.FullTeamInfo.FromTeamInfo(team_info, division, age_bracket, key=key) info_pb.put()
def _runParseTeamTest(self, twitter_id=None): self.SetHtmlResponse(FAKE_TEAM_INFO_PAGE) params = { 'id': 'g%3d', 'division': 'OPEN', 'age_bracket': 'COLLEGE', } response = self.testapp.get('/tasks/sr/crawl_team', params=params) self.assertEqual(200, response.status_int) id = 'njcj4s6Ct8EmLJyC98tkMEP3YQC5QiKs33MnNEu9jp0%3d' # 1. Check the Team info in the datastore query = game_model.Team.query() teams = query.fetch(1000) self.assertEqual(1, len(teams)) # Full team ID as crawled from FAKE_TEAM_INFO_PAGE. self.assertEqual(id, teams[0].score_reporter_id) self.assertEqual(twitter_id, teams[0].twitter_id) # 2. Check the FullTeamInfo in the datastore query = game_model.FullTeamInfo.query() teams = query.fetch(1000) self.assertEqual(1, len(teams)) key = game_model.full_team_info_key(id) self.assertEqual('https://www.facebook.com/TexasUltimate', teams[0].facebook_url) self.assertEqual(scores_messages.AgeBracket.COLLEGE, teams[0].age_bracket) self.assertEqual(scores_messages.Division.OPEN, teams[0].division) self.assertEqual('Texas (TUFF)', teams[0].name) self.assertEqual('texasultimate', teams[0].screen_name) self.assertEqual('http://texasultimate.wix.com/texasultimate', teams[0].website) self.assertEqual(id, teams[0].id) # 3. Check the TeamIdLookup in the datastore query = game_model.TeamIdLookup.query() items = query.fetch(1000) self.assertEqual(1, len(items)) self.assertEqual(id, items[0].score_reporter_id) self.assertEqual(1, len(items[0].score_reporter_tourney_id)) self.assertEqual('g%3d', items[0].score_reporter_tourney_id[0])
def _AddScoreReporterAccountInfo(score_reporter_account): """Populate ScoreReporterAccount with additional data from the datastore. Args: score_reporter_account: scores_messages.ScoreReporterAccount object """ id = score_reporter_account.id if not id: return info = game_model.full_team_info_key(id).get() if not info: return score_reporter_account.name = info.name score_reporter_account.team_website = info.website score_reporter_account.facebook_url = info.facebook_url score_reporter_account.profile_image_url_https = '%s%s' % ( USAU_PREFIX, info.image_link) score_reporter_account.coach = info.coach score_reporter_account.asst_coach = info.asst_coach score_reporter_account.screen_name = info.screen_name
def testGetGames_scoreReporterGame(self, mock_add_queue, mock_app_identity): """Verify the API handles the case where a SR game is returned.""" mock_app_identity.get_default_version_hostname = mock.MagicMock() mock_app_identity.get_default_version_hostname.return_value = 'production host' user = self.CreateUser(2, 'bob') user.put() teams = [ game_model.Team(score_reporter_id='a'), game_model.Team(score_reporter_id='b') ] info = score_reporter_crawler.GameInfo( 'a', 'b', 'name', scores_messages.Division.WOMENS, scores_messages.AgeBracket.NO_RESTRICTION) info.home_team_link = 'c' info.away_team_link = 'd' team_tourney_map = { 'c': 'e', 'd': 'f', } game = game_model.Game.FromGameInfo(info, team_tourney_map) game.put() self.assertGameDbSize(1) team_info = game_model.FullTeamInfo( key=game_model.full_team_info_key('e'), id='e', name='name', age_bracket=scores_messages.AgeBracket.NO_RESTRICTION, division=scores_messages.Division.WOMENS, website='website', screen_name='twitter_screenname', facebook_url='facebook_url', image_link='image_link', coach='coach', asst_coach='asst_coach') team_info.put() # Request with all operators request = scores_messages.GamesRequest() request.league = scores_messages.League.USAU request.division = scores_messages.Division.WOMENS request.age_bracket = scores_messages.AgeBracket.NO_RESTRICTION response = self.api.GetGames(request) self.assertEquals(1, len(response.games)) self.assertEquals(2, len(response.games[0].teams)) account = scores_messages.ScoreReporterAccount( id='e', name='name', team_website='website', facebook_url='facebook_url', screen_name='twitter_screenname', profile_image_url_https='%s%s' % (scores_api.USAU_PREFIX, 'image_link'), coach='coach', asst_coach='asst_coach') self.assertEquals(account, response.games[0].teams[0].score_reporter_account) account = scores_messages.ScoreReporterAccount(id='f') self.assertEquals(account, response.games[0].teams[1].score_reporter_account)
def testGetGames_scoreReporterGame(self, mock_add_queue, mock_app_identity): """Verify the API handles the case where a SR game is returned.""" mock_app_identity.get_default_version_hostname = mock.MagicMock() mock_app_identity.get_default_version_hostname.return_value = 'production host' user = self.CreateUser(2, 'bob') user.put() teams = [game_model.Team(score_reporter_id='a'), game_model.Team(score_reporter_id='b')] info = score_reporter_crawler.GameInfo( 'a', 'b', 'name', scores_messages.Division.WOMENS, scores_messages.AgeBracket.NO_RESTRICTION) info.home_team_link = 'c' info.away_team_link = 'd' team_tourney_map = { 'c': 'e', 'd': 'f', } game = game_model.Game.FromGameInfo(info, team_tourney_map) game.put() self.assertGameDbSize(1) team_info = game_model.FullTeamInfo( key=game_model.full_team_info_key('e'), id='e', name='name', age_bracket=scores_messages.AgeBracket.NO_RESTRICTION, division=scores_messages.Division.WOMENS, website='website', screen_name='twitter_screenname', facebook_url='facebook_url', image_link='image_link', coach='coach', asst_coach='asst_coach') team_info.put() # Request with all operators request = scores_messages.GamesRequest() request.league = scores_messages.League.USAU request.division = scores_messages.Division.WOMENS request.age_bracket = scores_messages.AgeBracket.NO_RESTRICTION response = self.api.GetGames(request) self.assertEquals(1, len(response.games)) self.assertEquals(2, len(response.games[0].teams)) account = scores_messages.ScoreReporterAccount( id='e', name='name', team_website='website', facebook_url='facebook_url', screen_name='twitter_screenname', profile_image_url_https='%s%s' % (scores_api.USAU_PREFIX, 'image_link'), coach='coach', asst_coach='asst_coach') self.assertEquals(account, response.games[0].teams[0].score_reporter_account) account = scores_messages.ScoreReporterAccount(id='f') self.assertEquals(account, response.games[0].teams[1].score_reporter_account)