Adds "all_sources" field to Mobile API and video module Course Blocks

student_view_data.

Added to both places because the iOS app uses both APIs data to provide
downloadable videos.
This commit is contained in:
Jillian Vogel
2017-11-15 13:41:19 +10:30
parent c9c67e0827
commit cdcb4be077
5 changed files with 142 additions and 5 deletions

View File

@@ -798,6 +798,92 @@ class VideoExportTestCase(VideoDescriptorTestBase):
self.assertEqual(xml.get('display_name'), u'\u8fd9\u662f\u6587')
@ddt.ddt
@patch.object(settings, 'FEATURES', create=True, new={
'FALLBACK_TO_ENGLISH_TRANSCRIPTS': False,
})
class VideoDescriptorStudentViewDataTestCase(unittest.TestCase):
"""
Make sure that VideoDescriptor returns the expected student_view_data.
"""
VIDEO_URL_1 = 'http://www.example.com/source_low.mp4'
VIDEO_URL_2 = 'http://www.example.com/source_med.mp4'
VIDEO_URL_3 = 'http://www.example.com/source_high.mp4'
@ddt.data(
# Ensure no extra data is returned if video module configured only for web display.
(
{'only_on_web': True},
{'only_on_web': True},
),
# Ensure that the deprecated `source` attribute is included in the `all_sources` list.
(
{
'only_on_web': False,
'youtube_id_1_0': None,
'source': VIDEO_URL_1,
},
{
'only_on_web': False,
'duration': None,
'transcripts': {},
'encoded_videos': {
'fallback': {'url': VIDEO_URL_1, 'file_size': 0},
},
'all_sources': [VIDEO_URL_1],
},
),
# Ensure that `html5_sources` take precendence over deprecated `source` url
(
{
'only_on_web': False,
'youtube_id_1_0': None,
'source': VIDEO_URL_1,
'html5_sources': [VIDEO_URL_2, VIDEO_URL_3],
},
{
'only_on_web': False,
'duration': None,
'transcripts': {},
'encoded_videos': {
'fallback': {'url': VIDEO_URL_2, 'file_size': 0},
},
'all_sources': [VIDEO_URL_2, VIDEO_URL_3, VIDEO_URL_1],
},
),
# Ensure that YouTube URLs are included in `encoded_videos`, but not `all_sources`.
(
{
'only_on_web': False,
'youtube_id_1_0': 'abc',
'html5_sources': [VIDEO_URL_2, VIDEO_URL_3],
},
{
'only_on_web': False,
'duration': None,
'transcripts': {},
'encoded_videos': {
'fallback': {'url': VIDEO_URL_2, 'file_size': 0},
'youtube': {'url': 'https://www.youtube.com/watch?v=abc', 'file_size': 0},
},
'all_sources': [VIDEO_URL_2, VIDEO_URL_3],
},
),
)
@ddt.unpack
@patch('xmodule.video_module.video_module.is_val_transcript_feature_enabled_for_course')
def test_student_view_data(self, field_data, expected_student_view_data, mock_transcript_feature):
"""
Ensure that student_view_data returns the expected results for video modules.
"""
mock_transcript_feature.return_value = False
descriptor = instantiate_descriptor(**field_data)
descriptor.runtime.course_id = MagicMock()
student_view_data = descriptor.student_view_data()
self.assertEquals(student_view_data, expected_student_view_data)
@ddt.ddt
@patch.object(settings, 'YOUTUBE', create=True, new={
# YouTube JavaScript API

View File

@@ -977,6 +977,11 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
encoded_videos = {}
val_video_data = {}
all_sources = self.html5_sources or []
# `source` is a deprecated field, but we include it for backwards compatibility.
if self.source:
all_sources.append(self.source)
# Check in VAL data first if edx_video_id exists
if self.edx_video_id:
@@ -1008,10 +1013,9 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
# Fall back to other video URLs in the video module if not found in VAL
if not encoded_videos:
video_url = self.html5_sources[0] if self.html5_sources else self.source
if video_url:
if all_sources:
encoded_videos["fallback"] = {
"url": video_url,
"url": all_sources[0],
"file_size": 0, # File size is unknown for fallback URLs
}
@@ -1036,4 +1040,5 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
"duration": val_video_data.get('duration', None),
"transcripts": transcripts,
"encoded_videos": encoded_videos,
"all_sources": all_sources,
}