def test_media_updated(self):
        affected_refs = {
            'references': {ndb.Key(Team, 'frc254'),
                           ndb.Key(Team, 'frc604')},
            'year': {2014, 2015},
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.media_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 10)
        self.assertTrue(
            TeamYearMediaQuery('frc254', 2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearMediaQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(TeamSocialMediaQuery('frc254').cache_key in cache_keys)
        self.assertTrue(
            TeamYearMediaQuery('frc604', 2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearMediaQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(TeamSocialMediaQuery('frc604').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)
예제 #2
0
def media_updated(affected_refs):
    reference_keys = filter(None, affected_refs['references'])
    years = filter(None, affected_refs['year'])

    team_keys = filter(lambda x: x.kind() == 'Team', reference_keys)
    event_team_keys_future = EventTeam.query(
        EventTeam.team.IN(team_keys)).fetch_async(
            None, keys_only=True) if team_keys else None

    queries_and_keys = []
    for reference_key in reference_keys:
        if reference_key.kind() == 'Team':
            for year in years:
                queries_and_keys.append(
                    (TeamYearMediaQuery(reference_key.id(), year)))
            queries_and_keys.append((TeamSocialMediaQuery(reference_key.id())))
        if reference_key.kind() == 'Event':
            queries_and_keys.append((EventMediasQuery(reference_key.id())))

    if event_team_keys_future:
        for event_team_key in event_team_keys_future.get_result():
            event_key = event_team_key.id().split('_')[0]
            year = int(event_key[:4])
            if year in years:
                queries_and_keys.append(EventTeamsMediasQuery(event_key))
                queries_and_keys.append(
                    EventTeamsPreferredMediasQuery(event_key))

    return queries_and_keys
예제 #3
0
    def _render(self, team_key):
        social_medias, self._last_modified = TeamSocialMediaQuery(
            team_key).fetch(dict_version=3, return_updated=True)

        return json.dumps(social_medias,
                          ensure_ascii=True,
                          indent=2,
                          sort_keys=True)
    def test_media_updated_team(self):
        affected_refs = {
            'references': {ndb.Key(Team, 'frc254'),
                           ndb.Key(Team, 'frc604')},
            'year': {2014, 2015},
            'media_tag_enum':
            {MediaTag.CHAIRMANS_ESSAY, MediaTag.CHAIRMANS_VIDEO},
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.media_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 22)
        self.assertTrue(
            TeamYearMediaQuery('frc254', 2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearMediaQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(TeamSocialMediaQuery('frc254').cache_key in cache_keys)
        self.assertTrue(
            TeamYearMediaQuery('frc604', 2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearMediaQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(TeamSocialMediaQuery('frc604').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)
        self.assertTrue(
            TeamTagMediasQuery('frc254', MediaTag.CHAIRMANS_ESSAY).cache_key in
            cache_keys)
        self.assertTrue(
            TeamTagMediasQuery('frc604', MediaTag.CHAIRMANS_VIDEO).cache_key in
            cache_keys)
        self.assertTrue(
            TeamYearTagMediasQuery('frc254', MediaTag.CHAIRMANS_ESSAY,
                                   2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearTagMediasQuery('frc604', MediaTag.CHAIRMANS_VIDEO,
                                   2015).cache_key in cache_keys)