Commit 04413bc6 by muhammad-ammar

don't re-raise exception if video image is not found

parent 6ebddd02
...@@ -19,8 +19,7 @@ from edxval.exceptions import ( # pylint: disable=unused-import ...@@ -19,8 +19,7 @@ from edxval.exceptions import ( # pylint: disable=unused-import
ValInternalError, ValInternalError,
ValVideoNotFoundError, ValVideoNotFoundError,
ValCannotCreateError, ValCannotCreateError,
ValCannotUpdateError, ValCannotUpdateError
ValVideoImageNotFoundError
) )
logger = logging.getLogger(__name__) # pylint: disable=C0103 logger = logging.getLogger(__name__) # pylint: disable=C0103
...@@ -154,7 +153,7 @@ def get_course_video_image_url(course_id=None, edx_video_id=None, video_image=No ...@@ -154,7 +153,7 @@ def get_course_video_image_url(course_id=None, edx_video_id=None, video_image=No
video_image: VideoImage instance video_image: VideoImage instance
Returns: Returns:
course video image url course video image url or None if no image found
""" """
storage = get_video_image_storage() storage = get_video_image_storage()
...@@ -162,7 +161,7 @@ def get_course_video_image_url(course_id=None, edx_video_id=None, video_image=No ...@@ -162,7 +161,7 @@ def get_course_video_image_url(course_id=None, edx_video_id=None, video_image=No
if video_image is None: if video_image is None:
video_image = CourseVideo.objects.get(course_id=course_id, video__edx_video_id=edx_video_id).video_image video_image = CourseVideo.objects.get(course_id=course_id, video__edx_video_id=edx_video_id).video_image
except ObjectDoesNotExist: except ObjectDoesNotExist:
raise ValVideoImageNotFoundError return None
return storage.url(video_image.image.name) return storage.url(video_image.image.name)
...@@ -179,7 +178,6 @@ def update_video_image(edx_video_id, course_id, image_data, file_name): ...@@ -179,7 +178,6 @@ def update_video_image(edx_video_id, course_id, image_data, file_name):
Raises: Raises:
Raises ValVideoNotFoundError if the CourseVideo cannot be retrieved. Raises ValVideoNotFoundError if the CourseVideo cannot be retrieved.
Raises ValVideoImageNotFoundError if the VideoImage cannot be retrieved.
""" """
try: try:
course_video = CourseVideo.objects.get(course_id=course_id, video__edx_video_id=edx_video_id) course_video = CourseVideo.objects.get(course_id=course_id, video__edx_video_id=edx_video_id)
......
...@@ -48,10 +48,3 @@ class ValCannotUpdateError(ValError): ...@@ -48,10 +48,3 @@ class ValCannotUpdateError(ValError):
This error is raised when an object cannot be updated This error is raised when an object cannot be updated
""" """
pass pass
class ValVideoImageNotFoundError(ValError):
"""
This error is raised when a video image is not found
"""
pass
...@@ -1235,6 +1235,14 @@ class CourseVideoImageTest(TestCase): ...@@ -1235,6 +1235,14 @@ class CourseVideoImageTest(TestCase):
image_url = api.get_course_video_image_url(self.course_id, self.edx_video_id) image_url = api.get_course_video_image_url(self.course_id, self.edx_video_id)
self.assertEqual(self.image_url, image_url) self.assertEqual(self.image_url, image_url)
def test_get_course_video_image_url_no_image(self):
"""
Verify that `get_course_video_image_url` api function returns None when no image is found.
"""
self.course_video.video_image.delete()
image_url = api.get_course_video_image_url(self.course_id, self.edx_video_id)
self.assertIsNone(image_url)
def test_get_videos_for_course(self): def test_get_videos_for_course(self):
""" """
Verify that `get_videos_for_course` api function has correct course_video_image_url. Verify that `get_videos_for_course` api function has correct course_video_image_url.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment