def test_invalid_image_file_info(self): """ Test that when no file information is provided to validate_video_image, it gives proper error message. """ error = validate_video_image({}) self.assertEquals( error, 'The image must have name, content type, and size information.')
def test_corrupt_image_file(self): """ Test that when corrupt file is provided to validate_video_image, it gives proper error message. """ with open(settings.MEDIA_ROOT + '/test-corrupt-image.png', 'w+') as image_file: uploaded_image_file = UploadedFile( image_file, content_type='image/png', size=settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MIN_BYTES'] ) error = validate_video_image(uploaded_image_file) self.assertEquals(error, 'There is a problem with this image file. Try to upload a different file.')
def video_images_handler(request, course_key_string, edx_video_id=None): # respond with a 404 if image upload is not enabled. if not WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED): return HttpResponseNotFound() if 'file' not in request.FILES: return JsonResponse({'error': _(u'An image file is required.')}, status=400) image_file = request.FILES['file'] error = validate_video_image(image_file) if error: return JsonResponse({'error': error}, status=400) with closing(image_file): image_url = update_video_image(edx_video_id, course_key_string, image_file, image_file.name) LOGGER.info( u'VIDEOS: Video image uploaded for edx_video_id [%s] in course [%s]', edx_video_id, course_key_string ) return JsonResponse({'image_url': image_url})
def video_images_handler(request, course_key_string, edx_video_id=None): # respond with a 404 if image upload is not enabled. if not WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED): return HttpResponseNotFound() if 'file' not in request.FILES: return JsonResponse({'error': _(u'An image file is required.')}, status=400) image_file = request.FILES['file'] error = validate_video_image(image_file) if error: return JsonResponse({'error': error}, status=400) with closing(image_file): image_url = update_video_image(edx_video_id, course_key_string, image_file, image_file.name) LOGGER.info( 'VIDEOS: Video image uploaded for edx_video_id [%s] in course [%s]', edx_video_id, course_key_string ) return JsonResponse({'image_url': image_url})
def test_invalid_image_file_info(self): """ Test that when no file information is provided to validate_video_image, it gives proper error message. """ error = validate_video_image({}) self.assertEquals(error, 'The image must have name, content type, and size information.')