Beispiel #1
0
 def test_add_view(self):
     """If a video with the given ID exists, increment it's view count."""
     with build_video(self.build_user(), views=10) as video:
         eq_(cached_viewcount(video.id), 10)
         response = self._post(video.id)
         eq_(response.status_code, 200)
         eq_(cached_viewcount(video.id), 11)
Beispiel #2
0
 def test_cached(self):
     """If the view count is in the cache, return that count instead of the
     count in the database.
     """
     with build_video(self.user, views=10) as video:
         self.cache.set(VIEWS_KEY % video.id, 12)
         eq_(cached_viewcount(video.id), 12)
Beispiel #3
0
 def test_uncached(self):
     """If the view count isn't in the cache, pull it from the database and
     store  it in the cache.
     """
     with build_video(self.user, views=10) as video:
         eq_(self.cache.get(VIEWS_KEY % video.id), None)
         eq_(cached_viewcount(video.id), 10)
         eq_(self.cache.get(VIEWS_KEY % video.id), 10)
Beispiel #4
0
def details(request, video_id=None):
    """Landing page for video details."""
    video = get_object_or_404(Video, pk=video_id, state='complete')

    # Check if admin is marking this video for judging.
    if request.POST.get('admin_mark', None) is not None:
        if request.user.is_staff:
            video.judge_mark = True
            video.save()

    viewcount = cached_viewcount(video_id)
    tweet_text = TWEET_TEXT % {'video_title': video.title[0:90],
                               'link': ''}  # URL is now included via JS

    d = dict(video=video,
             viewcount=viewcount,
             page_type='video-view',
             tweet_text=tweet_text)

    return render(request, 'videos/details.html', d)
Beispiel #5
0
 def views_cached(self):
     """Retrieve the viewcount for this video from the cache."""
     from flicks.videos.util import cached_viewcount
     return cached_viewcount(self.id)
Beispiel #6
0
 def test_video_does_not_exist(self):
     """If the specified video doesn't exist, return None."""
     eq_(cached_viewcount(999999), None)