diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index 172ab8cc33..467b912ea0 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -342,7 +342,7 @@ class VideoModule(VideoFields, XModule): try: transcript = self.translation(request.GET.get('videoId')) - except TranscriptException as ex: + except (TranscriptException, NotFoundError) as ex: log.info(ex.message) response = Response(status=404) else: @@ -414,6 +414,9 @@ class VideoModule(VideoFields, XModule): Filenames naming: en: subs_videoid.srt.sjson non_en: uk_subs_videoid.srt.sjson + + Raises: + NotFoundError if for 'en' subtitles no asset is uploaded. """ if self.transcript_language == 'en': return asset(self.location, subs_id).data diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 731f11b2d1..d7e635f57a 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -161,6 +161,8 @@ class TestVideoTranscriptTranslation(TestVideo): self.item_descriptor.render('student_view') self.item = self.item_descriptor.xmodule_runtime.xmodule_instance + # Tests for `download` dispatch: + def test_language_is_not_supported(self): request = Request.blank('/download?language=ru') response = self.item.transcript(request=request, dispatch='download') @@ -177,6 +179,15 @@ class TestVideoTranscriptTranslation(TestVideo): response = self.item.transcript(request=request, dispatch='download') self.assertEqual(response.body, 'Subs!') + def test_download_en_no_sub(self): + request = Request.blank('/download?language=en') + response = self.item.transcript(request=request, dispatch='download') + self.assertEqual(response.status, '404 Not Found') + with self.assertRaises(NotFoundError): + self.item.get_transcript() + + # Tests for `translation` dispatch: + def test_translation_fails(self): # No videoId request = Request.blank('/translation?language=ru')