def test_store_at_intervals(self): """Test that the view count is written to the DB at certain intervals based on the view count. """ # Test each pair of (viewcount, # of view per save) for viewcount, per_save in [(0, 1), (100, 10)]: with build_video(self.user, views=viewcount) as video: # Add per_save - 1 views and ensure each time that the DB # hasn't been written to. for i in range(per_save - 1): add_view(video.id) eq_(self._get_views(video), viewcount) # The last view should trigger a write. add_view(video.id) eq_(self._get_views(video), viewcount + per_save)
def ajax_add_view(request): video_id = request.POST.get('video_id', None) if video_id is None: raise Http404 try: viewcount = add_view(video_id) except ValueError: raise Http404 # video_id is not an integer if viewcount is None: raise Http404 return HttpResponse()
def ajax_add_view(request): video_id = request.POST.get('video_id', None) if video_id is None: raise Http404 try: viewcount = add_view(int(video_id)) # Increment graphite stats statsd.incr('video_views') # Total view count statsd.incr('video_views_%s' % video_id) except ValueError: raise Http404 # video_id is not an integer if viewcount is None: raise Http404 return HttpResponse()
def test_video_does_not_exist(self): """If the specified video doesn't exist, return None.""" eq_(add_view(9999999), None)
def test_store_in_cache(self): """The most-up-to-date view count should be in the cache.""" with build_video(self.user, views=10) as video: add_view(video.id) eq_(self.cache.get(VIEWS_KEY % video.id), 11)