From acfa80a6634b7076a0c7c7682eff9a12520cfae2 Mon Sep 17 00:00:00 2001 From: Qubad786 Date: Tue, 4 Jul 2017 16:59:55 +0500 Subject: [PATCH] Override video's `youtube_id_1_0` with val yt id on save. --- .../xmodule/video_module/video_module.py | 10 ++++++++++ .../courseware/tests/test_video_mongo.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index e38d90301f..4cdcfbb47f 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -506,6 +506,16 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler if metadata_was_changed_by_user: self.edx_video_id = 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 + # saves the video second time. This is because of the syncing of basic and advanced video settings which + # also syncs val youtube id from basic tab's `Video Url` to advanced tab's `Youtube ID`. + if self.edx_video_id and edxval_api: + val_youtube_id = edxval_api.get_url_for_profile(self.edx_video_id, 'youtube') + if val_youtube_id and self.youtube_id_1_0 != val_youtube_id: + self.youtube_id_1_0 = val_youtube_id + manage_video_subtitles_save( self, user, diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 0cbc036bf6..266a97bbc1 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -1197,6 +1197,24 @@ class TestEditorSavedMethod(BaseTestXmodule): item.editor_saved(self.user, old_metadata, None) self.assertEqual(item.edx_video_id, stripped_video_id) + @ddt.data(TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE) + @patch('xmodule.video_module.video_module.edxval_api.get_url_for_profile', Mock(return_value='test_yt_id')) + def test_editor_saved_with_yt_val_profile(self, default_store): + """ + Verify editor saved overrides `youtube_id_1_0` when a youtube val profile is there + for a given `edx_video_id`. + """ + self.MODULESTORE = default_store + self.initialize_module(metadata=self.metadata) + item = self.store.get_item(self.item_descriptor.location) + self.assertEqual(item.youtube_id_1_0, '3_yD_cEKoCk') + + # Now, modify `edx_video_id` and save should override `youtube_id_1_0`. + old_metadata = own_metadata(item) + item.edx_video_id = unicode(uuid4()) + item.editor_saved(self.user, old_metadata, None) + self.assertEqual(item.youtube_id_1_0, 'test_yt_id') + @ddt.ddt class TestVideoDescriptorStudentViewJson(TestCase):