def award_updated(affected_refs): event_keys = _filter(affected_refs['event']) team_keys = _filter(affected_refs['team_list']) years = _filter(affected_refs['year']) event_types = _filter(affected_refs['event_type_enum']) award_types = _filter(affected_refs['award_type_enum']) queries_and_keys = [] for event_key in event_keys: queries_and_keys.append((EventAwardsQuery(event_key.id()))) for team_key in team_keys: queries_and_keys.append( (TeamEventAwardsQuery(team_key.id(), event_key.id()))) for team_key in team_keys: queries_and_keys.append((TeamAwardsQuery(team_key.id()))) for year in years: queries_and_keys.append((TeamYearAwardsQuery(team_key.id(), year))) for event_type in event_types: for award_type in award_types: queries_and_keys.append( (TeamEventTypeAwardsQuery(team_key.id(), event_type, award_type))) return queries_and_keys
def test_award_updated(self): affected_refs = { 'event': {ndb.Key(Event, '2015casj'), ndb.Key(Event, '2015cama')}, 'team_list': {ndb.Key(Team, 'frc254'), ndb.Key(Team, 'frc604')}, 'year': {2014, 2015}, 'event_type_enum': {EventType.REGIONAL, EventType.DISTRICT}, 'award_type_enum': {AwardType.WINNER, AwardType.CHAIRMANS}, } cache_keys = [q.cache_key for q in get_affected_queries.award_updated(affected_refs)] self.assertEqual(len(cache_keys), 20) self.assertTrue(EventAwardsQuery('2015casj').cache_key in cache_keys) self.assertTrue(EventAwardsQuery('2015cama').cache_key in cache_keys) self.assertTrue(TeamAwardsQuery('frc254').cache_key in cache_keys) self.assertTrue(TeamAwardsQuery('frc604').cache_key in cache_keys) self.assertTrue(TeamYearAwardsQuery('frc254', 2014).cache_key in cache_keys) self.assertTrue(TeamYearAwardsQuery('frc254', 2015).cache_key in cache_keys) self.assertTrue(TeamYearAwardsQuery('frc604', 2014).cache_key in cache_keys) self.assertTrue(TeamYearAwardsQuery('frc604', 2015).cache_key in cache_keys) self.assertTrue(TeamEventAwardsQuery('frc254', '2015casj').cache_key in cache_keys) self.assertTrue(TeamEventAwardsQuery('frc254', '2015cama').cache_key in cache_keys) self.assertTrue(TeamEventAwardsQuery('frc604', '2015casj').cache_key in cache_keys) self.assertTrue(TeamEventAwardsQuery('frc604', '2015cama').cache_key in cache_keys) for team_key in ['frc254', 'frc604']: for event_type in [EventType.REGIONAL, EventType.DISTRICT]: for award_type in [AwardType.WINNER, AwardType.CHAIRMANS]: self.assertTrue(TeamEventTypeAwardsQuery(team_key, event_type, award_type).cache_key in cache_keys)