Commit f7c9245a by muhammad-ammar

address feedback

parent 46671d8e
......@@ -174,7 +174,10 @@ def update_video_image(edx_video_id, course_id, image_data, file_name):
course_id=course_id, video__edx_video_id=edx_video_id
)
except ObjectDoesNotExist:
error_message = u'CourseVideo not found for edx_video_id: {0}'.format(edx_video_id)
error_message = u'VAL: CourseVideo not found for edx_video_id: {0} and course_id: {1}'.format(
edx_video_id,
course_id
)
raise ValVideoNotFoundError(error_message)
video_image, _ = VideoImage.create_or_update(course_video, file_name, image_data)
......@@ -490,13 +493,11 @@ def copy_course_videos(source_course_id, destination_course_id):
video=course_video.video,
course_id=destination_course_id
)
try:
if hasattr(course_video, 'video_image'):
VideoImage.create_or_update(
course_video=destination_course_video,
file_name=course_video.video_image.image.name
)
except VideoImage.DoesNotExist:
pass
def export_to_xml(edx_video_id, course_id=None):
......
......@@ -1227,12 +1227,12 @@ class VideoStatusUpdateTest(TestCase):
class CourseVideoImageTest(TestCase):
"""
Tests to check course video image related functions works correctly
Tests to check course video image related functions works correctly.
"""
def setUp(self):
"""
Creates video objects for courses
Creates video objects for courses.
"""
self.course_id = 'test-course'
self.course_id2 = 'test-course2'
......@@ -1308,7 +1308,7 @@ class CourseVideoImageTest(TestCase):
@patch('edxval.models.logger')
def test_create_or_update_logging(self, mock_logger):
"""
Tests correct message is logged when save to storge is failed in `create_or_update`
Tests correct message is logged when save to storge is failed in `create_or_update`.
"""
with self.assertRaises(Exception) as save_exception: # pylint: disable=unused-variable
VideoImage.create_or_update(self.course_video, 'test.jpg', open(self.image_path2))
......@@ -1318,3 +1318,20 @@ class CourseVideoImageTest(TestCase):
self.course_video.course_id,
self.course_video.video.edx_video_id
)
def test_update_video_image_exception(self):
"""
Tests exception message when we hit by an exception in `update_video_image`.
"""
does_not_course_id = 'does_not_exist'
with self.assertRaises(Exception) as get_exception:
api.update_video_image(self.edx_video_id, does_not_course_id, open(self.image_path2), 'test.jpg')
self.assertEqual(
get_exception.exception.message,
u'VAL: CourseVideo not found for edx_video_id: {0} and course_id: {1}'.format(
self.edx_video_id,
does_not_course_id
)
)
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