def _get_events_cache_keys_and_controllers(cls, event_keys): cache_keys_and_controllers = [] for event_key in filter(None, event_keys): cache_keys_and_controllers.append((ApiEventController.get_cache_key_from_format(event_key.id()), ApiEventController)) cache_keys_and_controllers.append((ApiEventStatsController.get_cache_key_from_format(event_key.id()), ApiEventStatsController)) cache_keys_and_controllers.append((ApiEventRankingsController.get_cache_key_from_format(event_key.id()), ApiEventRankingsController)) return cache_keys_and_controllers
def _clear_events_controllers(cls, event_keys): for event_key in filter(None, event_keys): ApiEventController.clear_cache(event_key.id()) ApiEventStatsController.clear_cache(event_key.id()) ApiEventRankingsController.clear_cache(event_key.id())
def setUp(self): app = webapp2.WSGIApplication([ webapp2.Route(r'/api/v2/team/<team_key:>', ApiTeamController, methods=['GET']), webapp2.Route(r'/api/v2/team/<team_key:>/<year:([0-9]*)>', ApiTeamController, methods=['GET']), webapp2.Route(r'/api/v2/event/<event_key:>', ApiEventController, methods=['GET']), webapp2.Route(r'/api/v2/event/<event_key:>/teams', ApiEventTeamsController, methods=['GET']), webapp2.Route(r'/api/v2/event/<event_key:>/matches', ApiEventMatchesController, methods=['GET']), webapp2.Route(r'/api/v2/event/<event_key:>/stats', ApiEventStatsController, methods=['GET']), webapp2.Route(r'/api/v2/event/<event_key:>/rankings', ApiEventRankingsController, methods=['GET']), webapp2.Route(r'/api/v2/event/<event_key:>/awards', ApiEventAwardsController, methods=['GET']), webapp2.Route(r'/api/v2/events/<year:([0-9]*)>', ApiEventListController, methods=['GET']), ], debug=True) self.testapp = webtest.TestApp(app) self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_urlfetch_stub() self.testbed.init_memcache_stub() self.testbed.init_taskqueue_stub() # populate mini db self.event_2010sc_1 = Event( id='2010sc', name='Palmetto Regional', event_type_enum=EventType.REGIONAL, short_name='Palmetto', event_short='sc', year=2010, end_date=datetime(2010, 03, 27), official=True, location='Clemson, SC', start_date=datetime(2010, 03, 24), ) self.event_2010sc_2 = Event( id='2010sc', name='New Regional', event_type_enum=EventType.REGIONAL, short_name='Palmetto', event_short='sc', year=2010, end_date=datetime(2010, 03, 27), official=True, location='Clemson, SC', start_date=datetime(2010, 03, 24), ) self.team_frc1_1 = Team( id='frc1', name='This is a name', team_number=1, nickname='NICKNAME', address='San Jose, CA, USA', website='www.usfirst.org', ) self.team_frc1_2 = Team( id='frc1', name='This is a name', team_number=1, nickname='NICKNAME', address='San Jose, CA, USA', website='www.thebluealliance.com', ) self.team_frc2_1 = Team( id='frc2', name='This is a name', team_number=2, nickname='NICKNAME', address='San Jose, CA, USA', website='www.usfirst.org', ) self.team_frc2_2 = Team( id='frc2', name='This is a name', team_number=2, nickname='nickname', address='San Jose, CA, USA', website='www.usfirst.org', ) self.eventteam_2010sc_frc1 = EventTeam( id='2010sc_frc1', event=self.event_2010sc_1.key, team=self.team_frc1_1.key, year=2010, ) self.eventteam_2010sc_frc2 = EventTeam( id='2010sc_frc2', event=self.event_2010sc_1.key, team=self.team_frc2_1.key, year=2010, ) self.match1_1 = Match( id='2010sc_qm1', alliances_json=json.dumps({'blue': {'score': -1, 'teams': ['frc1', 'frc2', 'frc3']}, 'red': {'score': -1, 'teams': ['frc4', 'frc5', 'frc6']}}), comp_level='qm', event=self.event_2010sc_1.key, set_number=1, match_number=1, game='frc_unknown', team_key_names=[u'frc1', u'frc2', u'frc3', u'frc4', u'frc5', u'frc6'], ) self.match1_2 = Match( id='2010sc_qm1', alliances_json=json.dumps({'blue': {'score': -1, 'teams': ['frc1', 'frc999', 'frc3']}, 'red': {'score': -1, 'teams': ['frc4', 'frc5', 'frc6']}}), comp_level='qm', event=self.event_2010sc_1.key, set_number=1, match_number=1, game='frc_unknown', team_key_names=[u'frc1', u'frc999', u'frc3', u'frc4', u'frc5', u'frc6'], ) self.award1_1 = Award( id="2010sc_1", name_str="Regional Champion", award_type_enum=AwardType.WINNER, year=2010, event=self.event_2010sc_1.key, event_type_enum=EventType.REGIONAL, team_list=[self.team_frc1_1.key], recipient_json_list=[json.dumps({'team_number': 1, 'awardee': None})], ) self.award1_2 = Award( id="2010sc_1", name_str="Regional Champion", award_type_enum=AwardType.WINNER, year=2010, event=self.event_2010sc_1.key, event_type_enum=EventType.REGIONAL, team_list=[self.team_frc2_1.key], recipient_json_list=[json.dumps({'team_number': 2, 'awardee': None})], ) self.eventlist_2010_cache_key = ApiEventListController._get_full_cache_key(ApiEventListController.CACHE_KEY_FORMAT.format('2010')) self.event_2010sc_cache_key = ApiEventController._get_full_cache_key(ApiEventController.CACHE_KEY_FORMAT.format('2010sc')) self.eventteams_2010sc_cache_key = ApiEventTeamsController._get_full_cache_key(ApiEventTeamsController.CACHE_KEY_FORMAT.format('2010sc')) self.eventmatches_2010sc_cache_key = ApiEventMatchesController._get_full_cache_key(ApiEventMatchesController.CACHE_KEY_FORMAT.format('2010sc')) self.eventstats_2010sc_cache_key = ApiEventStatsController._get_full_cache_key(ApiEventStatsController.CACHE_KEY_FORMAT.format('2010sc')) self.eventrankings_2010sc_cache_key = ApiEventRankingsController._get_full_cache_key(ApiEventRankingsController.CACHE_KEY_FORMAT.format('2010sc')) self.eventawards_2010sc_cache_key = ApiEventAwardsController._get_full_cache_key(ApiEventAwardsController.CACHE_KEY_FORMAT.format('2010sc')) self.team_frc1_cache_key = ApiTeamController._get_full_cache_key(ApiTeamController.CACHE_KEY_FORMAT.format('frc1', 2010)) self.team_frc2_cache_key = ApiTeamController._get_full_cache_key(ApiTeamController.CACHE_KEY_FORMAT.format('frc2', 2010))