Commit aa309a8c by Nimisha Asthagiri

MA-182 Fix Mobile Subtitles.

parent ea18e5c3
...@@ -532,10 +532,10 @@ class VideoTranscriptsMixin(object): ...@@ -532,10 +532,10 @@ class VideoTranscriptsMixin(object):
# If we're not verifying the assets, we just trust our field values # If we're not verifying the assets, we just trust our field values
if not verify_assets: if not verify_assets:
if self.sub: translations = list(self.transcripts)
translations = ['en'] if not translations or self.sub:
translations += list(self.transcripts) translations += ['en']
return translations return set(translations)
# If we've gotten this far, we're going to verify that the transcripts # If we've gotten this far, we're going to verify that the transcripts
# being referenced are actually in the contentstore. # being referenced are actually in the contentstore.
......
...@@ -4,6 +4,7 @@ Tests for video outline API ...@@ -4,6 +4,7 @@ Tests for video outline API
import copy import copy
import ddt import ddt
from uuid import uuid4 from uuid import uuid4
from collections import namedtuple
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
...@@ -232,6 +233,34 @@ class TestVideoOutline(ModuleStoreTestCase, APITestCase): ...@@ -232,6 +233,34 @@ class TestVideoOutline(ModuleStoreTestCase, APITestCase):
course_outline = self._get_video_summary_list() course_outline = self._get_video_summary_list()
self.assertEqual(len(course_outline), 0) 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): def test_course_list_transcripts(self):
video = ItemFactory.create( video = ItemFactory.create(
parent_location=self.nameless_unit.location, parent_location=self.nameless_unit.location,
...@@ -239,20 +268,33 @@ class TestVideoOutline(ModuleStoreTestCase, APITestCase): ...@@ -239,20 +268,33 @@ class TestVideoOutline(ModuleStoreTestCase, APITestCase):
edx_video_id=self.edx_video_id, edx_video_id=self.edx_video_id,
display_name=u"test draft video omega 2 \u03a9" display_name=u"test draft video omega 2 \u03a9"
) )
transcript_case = namedtuple('transcript_case', ['transcripts', 'english_subtitle', 'expected_transcripts'])
transcript_cases = [ transcript_cases = [
({}, "en"), # defaults to english
({"en": 1}, "en"), transcript_case({}, "", ["en"]),
({"lang1": 1}, "lang1"), transcript_case({}, "en-sub", ["en"]),
({"lang1": 1, "en": 2}, "en"), # supports english
({"lang1": 1, "lang2": 2}, "lang1"), 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: for case in transcript_cases:
video.transcripts = transcript_case[0] video.transcripts = case.transcripts
video.sub = case.english_subtitle
modulestore().update_item(video, self.user.id) modulestore().update_item(video, self.user.id)
course_outline = self._get_video_summary_list() course_outline = self._get_video_summary_list()
self.assertEqual(len(course_outline), 1) 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): def test_transcripts_detail(self):
video = self._create_video_with_subs() video = self._create_video_with_subs()
......
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