Commit d5cee7b3 by sanfordstudent

Merge pull request #11471 from edx/sstudent/MA-1881-null-translation-check

ma-1881 handling empty translations and testing
parents fb45a6f3 24c4c8ab
......@@ -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 = '''
<video display_name="Test Video"
youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
show_captions="false"
download_track="false"
start_time="00:00:01"
download_video="false"
end_time="00:01:00">
<source src="http://www.example.com/source.mp4"/>
<track src="http://www.example.com/track"/>
<handout src="http://www.example.com/handout"/>
<transcript language="ge" src="subs_grmtran1.srt" />
<transcript language="hr" src="subs_croatian1.srt" />
</video>
'''
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'])
......@@ -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
......
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