示例#1
0
    def test_eventteam_updated(self):
        affected_refs = {
            'event': {ndb.Key(Event, '2015casj'), ndb.Key(Event, '2015cama')},
            'team': {ndb.Key(Team, 'frc254'), ndb.Key(Team, 'frc604')},
            'year': {2014, 2015}
        }
        cache_keys = [q.cache_key for q in get_affected_queries.eventteam_updated(affected_refs)]

        self.assertEqual(len(cache_keys), 24)
        self.assertTrue(TeamEventsQuery('frc254').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc604').cache_key in cache_keys)
        self.assertTrue(TeamParticipationQuery('frc254').cache_key in cache_keys)
        self.assertTrue(TeamParticipationQuery('frc604').cache_key in cache_keys)
        self.assertTrue(TeamYearEventsQuery('frc254', 2014).cache_key in cache_keys)
        self.assertTrue(TeamYearEventsQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(TeamYearEventsQuery('frc604', 2014).cache_key in cache_keys)
        self.assertTrue(TeamYearEventsQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(TeamYearEventTeamsQuery('frc254', 2014).cache_key in cache_keys)
        self.assertTrue(TeamYearEventTeamsQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(TeamYearEventTeamsQuery('frc604', 2014).cache_key in cache_keys)
        self.assertTrue(TeamYearEventTeamsQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2014, 0).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2014, 1).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2015, 0).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2015, 1).cache_key in cache_keys)
        self.assertTrue(EventTeamsQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(EventTeamsQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(EventEventTeamsQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(EventEventTeamsQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(EventTeamsMediasQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(EventTeamsMediasQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(EventTeamsPreferredMediasQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(EventTeamsPreferredMediasQuery('2015casj').cache_key in cache_keys)
 def _render(self, team_key, year):
     event_teams, self._last_modified = TeamYearEventTeamsQuery(
         team_key, int(year)).fetch(return_updated=True)
     statuses = {}
     for event_team in event_teams:
         status = event_team.status
         if status:
             status.update({
                 'alliance_status_str':
                 EventTeamStatusHelper.
                 generate_team_at_event_alliance_status_string(
                     team_key, status),
                 'playoff_status_str':
                 EventTeamStatusHelper.
                 generate_team_at_event_playoff_status_string(
                     team_key, status),
                 'overall_status_str':
                 EventTeamStatusHelper.generate_team_at_event_status_string(
                     team_key, status),
             })
         statuses[event_team.event.id()] = status
     return json.dumps(statuses,
                       ensure_ascii=True,
                       indent=2,
                       sort_keys=True)
    def test_district_updated(self):
        affected_refs = {
            'key': {ndb.Key(District, '2016ne')},
            'year': {2015, 2016},
            'abbreviation': {'ne', 'chs'}
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.district_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 13)
        self.assertTrue(DistrictsInYearQuery(2015).cache_key in cache_keys)
        self.assertTrue(DistrictsInYearQuery(2016).cache_key in cache_keys)
        self.assertTrue(DistrictHistoryQuery('ne').cache_key in cache_keys)
        self.assertTrue(DistrictHistoryQuery('chs').cache_key in cache_keys)
        self.assertTrue(DistrictQuery('2016ne').cache_key in cache_keys)
        self.assertTrue(TeamDistrictsQuery('frc604').cache_key in cache_keys)

        # Necessary because APIv3 Event models include the District model
        self.assertTrue(EventQuery('2016necmp').cache_key in cache_keys)
        self.assertTrue(EventListQuery(2016).cache_key in cache_keys)
        self.assertTrue(DistrictEventsQuery('2016ne').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc125').cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc125', 2016).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventTeamsQuery('frc125', 2016).cache_key in cache_keys)
        self.assertTrue(
            EventDivisionsQuery('2016necmp').cache_key in cache_keys)
    def test_event_updated(self):
        affected_refs = {
            'key': {ndb.Key(Event, '2015casj'),
                    ndb.Key(Event, '2015cama')},
            'year': {2014, 2015},
            'district_key':
            {ndb.Key(District, '2015fim'),
             ndb.Key(District, '2014mar')}
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.event_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 15)
        self.assertTrue(EventQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(EventQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(EventListQuery(2014).cache_key in cache_keys)
        self.assertTrue(EventListQuery(2015).cache_key in cache_keys)
        self.assertTrue(DistrictEventsQuery('2015fim').cache_key in cache_keys)
        self.assertTrue(DistrictEventsQuery('2014mar').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc254').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc604').cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventTeamsQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventTeamsQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(
            EventDivisionsQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(
            EventDivisionsQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(
            EventDivisionsQuery('2015cafoo').cache_key in cache_keys)
示例#5
0
def event_updated(affected_refs):
    event_keys = _filter(affected_refs['key'])
    years = _filter(affected_refs['year'])
    event_district_keys = _filter(affected_refs['district_key'])

    event_team_keys_future = EventTeam.query(
        EventTeam.event.IN([event_key for event_key in event_keys
                            ])).fetch_async(None, keys_only=True)
    events_future = ndb.get_multi_async(event_keys)

    queries_and_keys = []
    for event_key in event_keys:
        queries_and_keys.append((EventQuery(event_key.id())))
        queries_and_keys.append(EventDivisionsQuery(event_key.id()))

    for year in years:
        queries_and_keys.append((EventListQuery(year)))

    for event_district_key in event_district_keys:
        queries_and_keys.append((DistrictEventsQuery(event_district_key.id())))

    if event_keys:
        for et_key in event_team_keys_future.get_result():
            team_key = et_key.id().split('_')[1]
            year = int(et_key.id()[:4])
            queries_and_keys.append((TeamEventsQuery(team_key)))
            queries_and_keys.append((TeamYearEventsQuery(team_key, year)))
            queries_and_keys.append((TeamYearEventTeamsQuery(team_key, year)))

    events_with_parents = filter(
        lambda e: e.get_result() is not None and e.get_result().parent_event is
        not None, events_future)
    parent_keys = set(
        [e.get_result().parent_event for e in events_with_parents])
    for parent_key in parent_keys:
        queries_and_keys.append((EventDivisionsQuery(parent_key.id())))

    return queries_and_keys
示例#6
0
def eventteam_updated(affected_refs):
    event_keys = _filter(affected_refs['event'])
    team_keys = _filter(affected_refs['team'])
    years = _filter(affected_refs['year'])

    queries_and_keys = []
    for team_key in team_keys:
        queries_and_keys.append(TeamEventsQuery(team_key.id()))
        queries_and_keys.append(TeamParticipationQuery(team_key.id()))
        page_num = _get_team_page_num(team_key.id())
        for year in years:
            queries_and_keys.append(TeamYearEventsQuery(team_key.id(), year))
            queries_and_keys.append(
                TeamYearEventTeamsQuery(team_key.id(), year))
            queries_and_keys.append(TeamListYearQuery(year, page_num))

    for event_key in event_keys:
        queries_and_keys.append(EventTeamsQuery(event_key.id()))
        queries_and_keys.append(EventEventTeamsQuery(event_key.id()))
        queries_and_keys.append(EventTeamsMediasQuery(event_key.id()))
        queries_and_keys.append(EventTeamsPreferredMediasQuery(event_key.id()))

    return queries_and_keys