def testGetGames_gameTweetNoKnownTeams(self, mock_add_queue, mock_app_identity): """A game is returned with no known teams.""" mock_app_identity.get_default_version_hostname = mock.MagicMock() mock_app_identity.get_default_version_hostname.return_value = 'production host' twt = web_test_base.WebTestBase.CreateTweet( 1, ('bob', 2), created_at=datetime.utcnow()) teams = [ game_model.Team(twitter_id=2), game_model.Team(score_reporter_id='unknown') ] game = game_model.Game.FromTweet( twt, teams, [0, 0], scores_messages.Division.OPEN, scores_messages.AgeBracket.NO_RESTRICTION, scores_messages.League.USAU) game.put() self.assertGameDbSize(1) request = scores_messages.GamesRequest() request.league = scores_messages.League.USAU request.division = scores_messages.Division.OPEN 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))
def testGetGames_gameTweet(self, mock_add_queue, mock_app_identity): """Verify the API handles the case where a 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() twt = web_test_base.WebTestBase.CreateTweet( 1, ('bob', 2), created_at=datetime.utcnow()) teams = [game_model.Team(twitter_id=2), game_model.Team(twitter_id=3)] game = game_model.Game.FromTweet( twt, teams, [0, 0], scores_messages.Division.OPEN, scores_messages.AgeBracket.NO_RESTRICTION, scores_messages.League.USAU) game.put() self.assertGameDbSize(1) # Request with all operators request = scores_messages.GamesRequest() request.league = scores_messages.League.USAU request.division = scores_messages.Division.OPEN 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)) self.assertEquals( 'bob', response.games[0].teams[0].twitter_account.screen_name) self.assertEquals( 'bob', response.games[0].last_update_source.twitter_account.screen_name) # Request with no operators request = scores_messages.GamesRequest() response = self.api.GetGames(request) self.assertEquals(1, len(response.games)) # Request with wrong division operator request = scores_messages.GamesRequest() request.division = scores_messages.Division.MIXED response = self.api.GetGames(request) self.assertEquals(0, len(response.games)) # Request with wrong league operator request = scores_messages.GamesRequest() request.league = scores_messages.League.AUDL response = self.api.GetGames(request) self.assertEquals(0, len(response.games)) # Request with wrong age bracket operator request = scores_messages.GamesRequest() request.age_bracket = scores_messages.AgeBracket.MASTERS response = self.api.GetGames(request) self.assertEquals(0, len(response.games))
def testParseTourneyScores_newTourneyBothTeamsKnown(self, mock_add_queue): # Page with two teams, both of which have been added to the DB. self.SetHtmlResponse(FAKE_TOURNEY_SCORES_PAGE) params = { 'url_suffix': 'schedule/Men/College-Men/', 'name': 'my-tourney', 'division': 'OPEN', 'age_bracket': 'COLLEGE' } # One team has already been added to the database, but one is new. game_model.TeamIdLookup(score_reporter_id='123', score_reporter_tourney_id=['8%3d']).put() game_model.Team(twitter_id=5, score_reporter_id='123').put() game_model.TeamIdLookup(score_reporter_id='456', score_reporter_tourney_id=['g%3d']).put() response = self.testapp.get('/tasks/sr/crawl_tournament', params=params) self.assertEqual(200, response.status_int) calls = mock_add_queue.mock_calls self.assertEquals(0, len(calls)) full_url = '%s%s' % (score_reporter_crawler.EVENT_PREFIX, 'my_tourney/schedule/Men/College-Men/') game_query = game_model.Game.query() games = game_query.fetch(1000) self.assertEqual(1, len(games)) self.assertEqual(scores_messages.Division.OPEN, games[0].division) self.assertEqual(scores_messages.AgeBracket.COLLEGE, games[0].age_bracket) self.assertEqual('71984', games[0].id_str) self.assertEqual('my-tourney', games[0].tournament_id) self.assertEqual('my tourney', games[0].tournament_name) self.assertEqual([15, 13], games[0].scores) self.assertEqual('456', games[0].teams[0].score_reporter_id) self.assertEqual('123', games[0].teams[1].score_reporter_id) self.assertEqual(None, games[0].teams[0].twitter_id) self.assertEqual(5, games[0].teams[1].twitter_id)
def testParseTourneyScores_noTeamUrls(self, mock_add_queue): # Page with two teams, both of which have been added to the DB. self.SetHtmlResponse(FAKE_TOURNEY_NO_TEAM_URLS) params = { 'url_suffix': 'schedule/Men/College-Men/', 'name': 'my_tourney', 'division': 'OPEN', 'age_bracket': 'COLLEGE' } # One team has already been added to the database, but one is new. game_model.TeamIdLookup(score_reporter_id='123', score_reporter_tourney_id=['8%3d']).put() game_model.Team(twitter_id=5, score_reporter_id='123').put() game_model.TeamIdLookup(score_reporter_id='456', score_reporter_tourney_id=['g%3d']).put() response = self.testapp.get('/tasks/sr/crawl_tournament', params=params) self.assertEqual(200, response.status_int) calls = mock_add_queue.mock_calls self.assertEquals(0, len(calls)) game_query = game_model.Game.query() games = game_query.fetch(1000) self.assertEqual(0, len(games))
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 setUp(self): super(TeamEditorTest, self).setUp() self.testapp = webtest.TestApp(team_editor.app) game_model.Team(score_reporter_id='%3d').put() game_model.Team(score_reporter_id='%8d').put()
def testSanityGamesMessages(self): """Ensure no basic syntax errors in the model definition.""" game_model.Game() game_model.Team() game_model.GameSource()