Commit 2b576034 by cahrens

Handle case of video in a content library with no transcripts.

This partially addresses TNL-1776
parent e09f9ac4
......@@ -14,6 +14,7 @@ from xblock.core import XBlock
from xmodule.exceptions import NotFoundError
from xmodule.fields import RelativeTime
from opaque_keys.edx.locator import CourseLocator
from .transcripts_utils import (
get_or_create_sjson,
......@@ -166,6 +167,10 @@ class VideoStudentViewHandlers(object):
if not self.transcript_language == 'en':
return response
# If this video lives in library, the code below is not relevant and will error.
if not isinstance(self.course_id, CourseLocator):
return response
video_id = request.GET.get('videoId', None)
if video_id:
transcript_name = video_id
......
......@@ -569,11 +569,7 @@ class TestTranscriptTranslationGetDispatch(TestVideo):
Set course static_asset_path and ensure we get redirected to that path
if it isn't found in the contentstore
"""
self.course.static_asset_path = 'dummy/static'
self.course.save()
store = modulestore()
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
store.update_item(self.course, self.user.id)
self._set_static_asset_path()
if attach:
attach(self.item, sub)
......@@ -586,6 +582,27 @@ class TestTranscriptTranslationGetDispatch(TestVideo):
response.headerlist
)
@patch('xmodule.video_module.VideoModule.course_id', return_value='not_a_course_locator')
def test_translation_static_non_course(self, __):
"""
Test that get_static_transcript short-circuits in the case of a non-CourseLocator.
This fixes a bug for videos inside of content libraries.
"""
self._set_static_asset_path()
# When course_id is not mocked out, these values would result in 307, as tested above.
request = Request.blank('/translation/en?videoId=12345')
response = self.item.transcript(request=request, dispatch='translation/en')
self.assertEqual(response.status, '404 Not Found')
def _set_static_asset_path(self):
""" Helper method for setting up the static_asset_path information """
self.course.static_asset_path = 'dummy/static'
self.course.save()
store = modulestore()
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
store.update_item(self.course, self.user.id)
@attr('shard_1')
class TestStudioTranscriptTranslationGetDispatch(TestVideo):
......
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