def handle_noargs(self, verbosity=0, **options): if site_too_old(): return for v in models.Video.objects.exclude(thumbnail_url=''): if (not v.thumbnail or not default_storage.exists(v.thumbnail.name)): if verbosity >= 1: print >> sys.stderr, 'saving', repr(v), '(%i)' % v.pk try: # resave the thumbnail video_save_thumbnail.apply(args=(v.pk,)) except Exception: traceback.print_exc()
def test_data_saved(self): """ The thumbnail data for a video should be saved once this task is completed. """ thumbnail_url = 'http://pculture.org/not' video = self.create_video(update_index=False, has_thumbnail=True, thumbnail_url=thumbnail_url) thumbnail_data = open(self._data_file('logo.png'), 'r').read() remote_file = mock.Mock(read=lambda: thumbnail_data, getcode=lambda: 200) with mock.patch('localtv.tasks.urllib.urlopen', return_value=remote_file): video_save_thumbnail.apply(args=(video.pk,)) new_video = Video.objects.get(pk=video.pk) self.assertEqual(new_video.has_thumbnail, True) self.assertEqual(new_video.thumbnail_url, thumbnail_url) self.assertEqual(new_video.thumbnail_extension, 'png')
def test_data_saved(self): """ The thumbnail data for a video should be saved once this task is completed. """ thumbnail_url = 'http://pculture.org/path/to/logo.png' video = self.create_video(update_index=False, thumbnail_url=thumbnail_url) thumbnail_data = self._data_file('logo.png').read() remote_file = mock.Mock(read=lambda: thumbnail_data, getcode=lambda: 200) self.assertTrue(video.thumbnail._file is None) with mock.patch('localtv.tasks.urllib.urlopen', return_value=remote_file): video_save_thumbnail.apply(args=(video.pk, )) self.assertFalse(video.thumbnail is None) self.assertTrue(video.thumbnail._committed) new_video = Video.objects.get(pk=video.pk) self.assertTrue(new_video.thumbnail) self.assertTrue(new_video.thumbnail._committed) self.assertEqual(new_video.thumbnail_url, thumbnail_url)
def test_data_saved(self): """ The thumbnail data for a video should be saved once this task is completed. """ thumbnail_url = 'http://pculture.org/path/to/logo.png' video = self.create_video(update_index=False, thumbnail_url=thumbnail_url) thumbnail_data = self._data_file('logo.png').read() remote_file = mock.Mock(read=lambda: thumbnail_data, getcode=lambda: 200) self.assertTrue(video.thumbnail._file is None) with mock.patch('localtv.tasks.urllib.urlopen', return_value=remote_file): video_save_thumbnail.apply(args=(video.pk,)) self.assertFalse(video.thumbnail is None) self.assertTrue(video.thumbnail._committed) new_video = Video.objects.get(pk=video.pk) self.assertTrue(new_video.thumbnail) self.assertTrue(new_video.thumbnail._committed) self.assertEqual(new_video.thumbnail_url, thumbnail_url)