From edcd64e90f028b0c20bbb7af654f63e6bf3b82ad Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Fri, 14 Jul 2017 10:45:53 +0500 Subject: [PATCH] edx-videoi-id strip fix LEARNER-1871 --- .../xmodule/xmodule/video_module/video_module.py | 14 +++++++++----- .../courseware/tests/test_video_mongo.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index d72d48f1a7..f8271473e2 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -304,16 +304,20 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers, if xblock_settings and 'YOUTUBE_API_KEY' in xblock_settings: yt_api_key = xblock_settings['YOUTUBE_API_KEY'] + poster = None + if edxval_api and self.edx_video_id: + poster = edxval_api.get_course_video_image_url( + course_id=self.runtime.course_id.for_branch(None), + edx_video_id=self.edx_video_id.strip() + ) + metadata = { 'saveStateUrl': self.system.ajax_url + '/save_user_state', 'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False), 'streams': self.youtube_streams, 'sub': self.sub, 'sources': sources, - 'poster': edxval_api and edxval_api.get_course_video_image_url( - course_id=self.runtime.course_id.for_branch(None), - edx_video_id=self.edx_video_id.strip() - ), + 'poster': poster, # This won't work when we move to data that # isn't on the filesystem 'captionDataDir': getattr(self, 'data_dir', None), @@ -508,7 +512,7 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler break if metadata_was_changed_by_user: - self.edx_video_id = self.edx_video_id.strip() + self.edx_video_id = self.edx_video_id and self.edx_video_id.strip() # We want to override `youtube_id_1_0` with val youtube profile in the first place when someone adds/edits # an `edx_video_id` or its underlying YT val profile. Without this, override will only happen when a user diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index db323d5fc0..807a7e23cb 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -934,6 +934,19 @@ class TestGetHtmlMethod(BaseTestXmodule): self.assertIn('"poster": "/media/video-images/poster.png"', context) + @patch('xmodule.video_module.video_module.edxval_api.get_course_video_image_url') + def test_poster_image_without_edx_video_id(self, get_course_video_image_url): + """ + Verify that poster image is set to None and there is no crash when no edx_video_id. + """ + video_xml = '' + get_course_video_image_url.return_value = '/media/video-images/poster.png' + + self.initialize_module(data=video_xml) + context = self.item_descriptor.render(STUDENT_VIEW).content + + self.assertIn("\'poster\': \'null\'", context) + @attr(shard=1) class TestVideoCDNRewriting(BaseTestXmodule):