From e2ecb0db46c98932243df1a91299336178472980 Mon Sep 17 00:00:00 2001 From: Syed Hassan Raza Date: Wed, 21 Jan 2015 18:04:14 +0500 Subject: [PATCH] Invalid youtube_id raise NotFoundError for transcripts TNL-1229 --- common/lib/xmodule/xmodule/video_module/video_handlers.py | 5 ++++- lms/djangoapps/courseware/tests/test_video_handlers.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/video_module/video_handlers.py b/common/lib/xmodule/xmodule/video_module/video_handlers.py index 9e9db860ca..d785edec5b 100644 --- a/common/lib/xmodule/xmodule/video_module/video_handlers.py +++ b/common/lib/xmodule/xmodule/video_module/video_handlers.py @@ -104,6 +104,7 @@ class VideoStudentViewHandlers(object): Raises: NotFoundError if for 'en' subtitles no asset is uploaded. + NotFoundError if youtube_id does not exist / invalid youtube_id """ if youtube_id: # Youtube case: @@ -111,7 +112,9 @@ class VideoStudentViewHandlers(object): return Transcript.asset(self.location, youtube_id).data youtube_ids = youtube_speed_dict(self) - assert youtube_id in youtube_ids + if youtube_id not in youtube_ids: + log.info("Youtube_id %s does not exist", youtube_id) + raise NotFoundError try: sjson_transcript = Transcript.asset(self.location, youtube_id, self.transcript_language).data diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 0bf1dad60e..4d80952848 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -322,6 +322,11 @@ class TestTranscriptTranslationGetDispatch(TestVideo): response = self.item.transcript(request=request, dispatch='translation/ru') self.assertEqual(response.status, '404 Not Found') + # Youtube_id is invalid or does not exist + request = Request.blank('/translation/uk?videoId=9855256955511225') + response = self.item.transcript(request=request, dispatch='translation/uk') + self.assertEqual(response.status, '404 Not Found') + def test_translaton_en_youtube_success(self): subs = {"start": [10], "end": [100], "text": ["Hi, welcome to Edx."]} good_sjson = _create_file(json.dumps(subs))