From aa309a8caf1ce40ba7e675118e03120e5216f298 Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Wed, 10 Dec 2014 15:58:00 -0500 Subject: [PATCH] MA-182 Fix Mobile Subtitles. --- .../xmodule/video_module/transcripts_utils.py | 8 +-- .../mobile_api/video_outlines/tests.py | 58 ++++++++++++++++--- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py index e38dcd9fec..2c1a10e71c 100644 --- a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py +++ b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py @@ -532,10 +532,10 @@ class VideoTranscriptsMixin(object): # If we're not verifying the assets, we just trust our field values if not verify_assets: - if self.sub: - translations = ['en'] - translations += list(self.transcripts) - return translations + translations = list(self.transcripts) + if not translations or self.sub: + translations += ['en'] + return set(translations) # If we've gotten this far, we're going to verify that the transcripts # being referenced are actually in the contentstore. diff --git a/lms/djangoapps/mobile_api/video_outlines/tests.py b/lms/djangoapps/mobile_api/video_outlines/tests.py index ffc0303bc2..511e907c4c 100644 --- a/lms/djangoapps/mobile_api/video_outlines/tests.py +++ b/lms/djangoapps/mobile_api/video_outlines/tests.py @@ -4,6 +4,7 @@ Tests for video outline API import copy import ddt from uuid import uuid4 +from collections import namedtuple from django.core.urlresolvers import reverse from django.test.utils import override_settings @@ -232,6 +233,34 @@ class TestVideoOutline(ModuleStoreTestCase, APITestCase): course_outline = self._get_video_summary_list() self.assertEqual(len(course_outline), 0) + def test_course_list_language(self): + video = ItemFactory.create( + parent_location=self.nameless_unit.location, + category="video", + edx_video_id=self.edx_video_id, + display_name=u"test draft video omega 2 \u03a9" + ) + + language_case = namedtuple('language_case', ['transcripts', 'expected_language']) + language_cases = [ + # defaults to english + language_case({}, "en"), + # supports english + language_case({"en": 1}, "en"), + # supports another language + language_case({"lang1": 1}, "lang1"), + # returns first alphabetically-sorted language + language_case({"lang1": 1, "en": 2}, "en"), + language_case({"lang1": 1, "lang2": 2}, "lang1"), + ] + + for case in language_cases: + video.transcripts = case.transcripts + modulestore().update_item(video, self.user.id) + course_outline = self._get_video_summary_list() + self.assertEqual(len(course_outline), 1) + self.assertEqual(course_outline[0]['summary']['language'], case.expected_language) + def test_course_list_transcripts(self): video = ItemFactory.create( parent_location=self.nameless_unit.location, @@ -239,20 +268,33 @@ class TestVideoOutline(ModuleStoreTestCase, APITestCase): edx_video_id=self.edx_video_id, display_name=u"test draft video omega 2 \u03a9" ) + + transcript_case = namedtuple('transcript_case', ['transcripts', 'english_subtitle', 'expected_transcripts']) transcript_cases = [ - ({}, "en"), - ({"en": 1}, "en"), - ({"lang1": 1}, "lang1"), - ({"lang1": 1, "en": 2}, "en"), - ({"lang1": 1, "lang2": 2}, "lang1"), + # defaults to english + transcript_case({}, "", ["en"]), + transcript_case({}, "en-sub", ["en"]), + # supports english + transcript_case({"en": 1}, "", ["en"]), + transcript_case({"en": 1}, "en-sub", ["en"]), + # keeps both english and other languages + transcript_case({"lang1": 1, "en": 2}, "", ["lang1", "en"]), + transcript_case({"lang1": 1, "en": 2}, "en-sub", ["lang1", "en"]), + # adds english to list of languages only if english_subtitle is specified + transcript_case({"lang1": 1, "lang2": 2}, "", ["lang1", "lang2"]), + transcript_case({"lang1": 1, "lang2": 2}, "en-sub", ["lang1", "lang2", "en"]), ] - for transcript_case in transcript_cases: - video.transcripts = transcript_case[0] + for case in transcript_cases: + video.transcripts = case.transcripts + video.sub = case.english_subtitle modulestore().update_item(video, self.user.id) course_outline = self._get_video_summary_list() self.assertEqual(len(course_outline), 1) - self.assertEqual(course_outline[0]['summary']['language'], transcript_case[1]) + self.assertSetEqual( + set(course_outline[0]['summary']['transcripts'].keys()), + set(case.expected_transcripts) + ) def test_transcripts_detail(self): video = self._create_video_with_subs()