def _set_responses_xrange(self, *args, **kwargs): """Populate db with Video and mock URL responses for their subtitles""" for i in xrange(*args): youtube_id = str(i) Video(youtube_id=youtube_id).put() video_url = urllib.quote('http://www.youtube.com/watch?v=%s' % youtube_id) url = UNISUBS_API_URL % video_url self.set_response(url, content=kwargs.get('content', youtube_id), status_code=kwargs.get('status_code', 200))
def test_process_next_batch_on_nonempty_cursor(self): offset = 3 # these should be skipped, they'll DownloadError for i in xrange(0, offset): Video(youtube_id=str(i)).put() # these should be downloaded self._set_responses_xrange(offset, BATCH_SIZE + offset) query = Video.all() query.fetch(offset) cursor = query.cursor() _task_handler('UUID', cursor=cursor) self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)