コード例 #1
0
    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}
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.award_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 12)
        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)
コード例 #2
0
    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)
コード例 #3
0
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
コード例 #4
0
def award_updated(affected_refs):
    event_keys = filter(None, affected_refs['event'])
    team_keys = filter(None, affected_refs['team_list'])
    years = filter(None, affected_refs['year'])

    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)))

    return queries_and_keys
コード例 #5
0
    def _render(self, event_key):
        awards, self._last_modified = EventAwardsQuery(event_key).fetch(
            dict_version=3, return_updated=True)

        return json.dumps(awards, ensure_ascii=True, indent=2, sort_keys=True)