Commit 24c4c8ab by Sanford Student

ma-1881 handling empty translations and testing

using lists for json serializability, if that's a word
parent 481f3227
...@@ -920,3 +920,38 @@ class VideoDescriptorIndexingTestCase(unittest.TestCase): ...@@ -920,3 +920,38 @@ class VideoDescriptorIndexingTestCase(unittest.TestCase):
}, },
"content_type": "Video" "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): ...@@ -569,14 +569,15 @@ class VideoTranscriptsMixin(object):
Defaults to False Defaults to False
""" """
translations = [] 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 we're not verifying the assets, we just trust our field values
if not verify_assets: if not verify_assets:
translations = list(other_lang) if other_langs:
translations = list(other_langs)
if not translations or sub: if not translations or sub:
translations += ['en'] translations += ['en']
return set(translations) return 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.
...@@ -589,16 +590,16 @@ class VideoTranscriptsMixin(object): ...@@ -589,16 +590,16 @@ class VideoTranscriptsMixin(object):
except NotFoundError: except NotFoundError:
pass pass
else: else:
translations = ['en'] translations += ['en']
else: else:
translations = ['en'] translations += ['en']
for lang in other_lang: for lang in other_langs:
try: try:
Transcript.asset(self.location, None, None, other_lang[lang]) Transcript.asset(self.location, None, None, other_langs[lang])
except NotFoundError: except NotFoundError:
continue continue
translations.append(lang) translations += [lang]
return translations 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