From 24c4c8abedd98fdf4c252bc6c8dfd35191b66c95 Mon Sep 17 00:00:00 2001 From: Sanford Student Date: Mon, 8 Feb 2016 16:59:37 -0500 Subject: [PATCH] ma-1881 handling empty translations and testing using lists for json serializability, if that's a word --- .../lib/xmodule/xmodule/tests/test_video.py | 35 +++++++++++++++++++ .../xmodule/video_module/transcripts_utils.py | 17 ++++----- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_video.py b/common/lib/xmodule/xmodule/tests/test_video.py index fdcced4439..9790b8b208 100644 --- a/common/lib/xmodule/xmodule/tests/test_video.py +++ b/common/lib/xmodule/xmodule/tests/test_video.py @@ -920,3 +920,38 @@ class VideoDescriptorIndexingTestCase(unittest.TestCase): }, "content_type": "Video" }) + + def test_video_with_multiple_transcripts_translation_retrieval(self): + """ + Test translation retrieval of a video module with + multiple transcripts uploaded by a user. + """ + xml_data_transcripts = ''' + + ''' + + descriptor = instantiate_descriptor(data=xml_data_transcripts) + translations = descriptor.available_translations(descriptor.get_transcripts_info(), verify_assets=False) + self.assertEqual(translations, ['hr', 'ge']) + + def test_video_with_no_transcripts_translation_retrieval(self): + """ + Test translation retrieval of a video module with + no transcripts uploaded by a user- ie, that retrieval + does not throw an exception. + """ + descriptor = instantiate_descriptor(data=None) + translations = descriptor.available_translations(descriptor.get_transcripts_info(), verify_assets=False) + self.assertEqual(translations, ['en']) diff --git a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py index edf3e5b72e..2675000a8e 100644 --- a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py +++ b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py @@ -569,14 +569,15 @@ class VideoTranscriptsMixin(object): Defaults to False """ translations = [] - sub, other_lang = transcripts["sub"], transcripts["transcripts"] + sub, other_langs = transcripts["sub"], transcripts["transcripts"] # If we're not verifying the assets, we just trust our field values if not verify_assets: - translations = list(other_lang) + if other_langs: + translations = list(other_langs) if not translations or sub: translations += ['en'] - return set(translations) + return translations # If we've gotten this far, we're going to verify that the transcripts # being referenced are actually in the contentstore. @@ -589,16 +590,16 @@ class VideoTranscriptsMixin(object): except NotFoundError: pass else: - translations = ['en'] + translations += ['en'] else: - translations = ['en'] + translations += ['en'] - for lang in other_lang: + for lang in other_langs: try: - Transcript.asset(self.location, None, None, other_lang[lang]) + Transcript.asset(self.location, None, None, other_langs[lang]) except NotFoundError: continue - translations.append(lang) + translations += [lang] return translations