Commit 36d47dd0 by Oleg Marshev

Merge pull request #4527 from edx/oleg/xml-course-transcripts-fix

Fix transcripts in XML course when no static_asset_path is set.
parents d76c89f8 a340ad53
...@@ -11,7 +11,6 @@ from webob import Response ...@@ -11,7 +11,6 @@ from webob import Response
from xblock.core import XBlock from xblock.core import XBlock
from xmodule.course_module import CourseDescriptor
from xmodule.exceptions import NotFoundError from xmodule.exceptions import NotFoundError
from xmodule.fields import RelativeTime from xmodule.fields import RelativeTime
...@@ -196,12 +195,12 @@ class VideoStudentViewHandlers(object): ...@@ -196,12 +195,12 @@ class VideoStudentViewHandlers(object):
if transcript_name: if transcript_name:
# Get the asset path for course # Get the asset path for course
asset_path = None asset_path = None
if hasattr(self.descriptor.runtime, 'modulestore'): course = self.descriptor.runtime.modulestore.get_course(self.course_id)
course = self.descriptor.runtime.modulestore.get_course(self.course_id) if course.static_asset_path:
asset_path = course.static_asset_path asset_path = course.static_asset_path
else: else:
# Handle XML Courses that don't have modulestore in the runtime # It seems static_asset_path is not set in any XMLModuleStore courses.
asset_path = getattr(self.descriptor, 'data_dir', None) asset_path = getattr(course, 'data_dir', '')
if asset_path: if asset_path:
response = Response( response = Response(
...@@ -251,7 +250,7 @@ class VideoStudentViewHandlers(object): ...@@ -251,7 +250,7 @@ class VideoStudentViewHandlers(object):
try: try:
transcript = self.translation(request.GET.get('videoId', None)) transcript = self.translation(request.GET.get('videoId', None))
except NotFoundError, ex: except (TypeError, NotFoundError) as ex:
log.info(ex.message) log.info(ex.message)
# Try to return static URL redirection as last resort # Try to return static URL redirection as last resort
# if no translation is required # if no translation is required
......
...@@ -8,6 +8,7 @@ import textwrap ...@@ -8,6 +8,7 @@ import textwrap
import json import json
from datetime import timedelta from datetime import timedelta
from webob import Request from webob import Request
from mock import MagicMock, Mock
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore
...@@ -23,7 +24,6 @@ from xmodule.video_module.transcripts_utils import ( ...@@ -23,7 +24,6 @@ from xmodule.video_module.transcripts_utils import (
TranscriptException, TranscriptException,
TranscriptsGenerationException, TranscriptsGenerationException,
) )
from opaque_keys.edx.locations import AssetLocation
SRT_content = textwrap.dedent(""" SRT_content = textwrap.dedent("""
0 0
...@@ -401,16 +401,18 @@ class TestTranscriptTranslationGetDispatch(TestVideo): ...@@ -401,16 +401,18 @@ class TestTranscriptTranslationGetDispatch(TestVideo):
response = self.item.transcript(request=request, dispatch='translation/uk') response = self.item.transcript(request=request, dispatch='translation/uk')
self.assertDictEqual(json.loads(response.body), subs) self.assertDictEqual(json.loads(response.body), subs)
def test_translation_static_transcript(self): def test_translation_static_transcript_xml_with_data_dirc(self):
""" """
Set course static_asset_path and ensure we get redirected to that path Test id data_dir is set in XML course.
if it isn't found in the contentstore
Set course data_dir and ensure we get redirected to that path
if it isn't found in the contentstore.
""" """
self.course.static_asset_path = 'dummy/static' # Simulate data_dir set in course.
self.course.save() test_modulestore = MagicMock()
store = modulestore() attrs = {'get_course.return_value': Mock(data_dir='dummy/static', static_asset_path='')}
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id): test_modulestore.configure_mock(**attrs)
store.update_item(self.course, self.user.id) self.item_descriptor.runtime.modulestore = test_modulestore
# Test youtube style en # Test youtube style en
request = Request.blank('/translation/en?videoId=12345') request = Request.blank('/translation/en?videoId=12345')
...@@ -437,16 +439,16 @@ class TestTranscriptTranslationGetDispatch(TestVideo): ...@@ -437,16 +439,16 @@ class TestTranscriptTranslationGetDispatch(TestVideo):
response = self.item.transcript(request=request, dispatch='translation/uk') response = self.item.transcript(request=request, dispatch='translation/uk')
self.assertEqual(response.status, '404 Not Found') self.assertEqual(response.status, '404 Not Found')
def test_xml_transcript(self): def test_translation_static_transcript(self):
""" """
Set data_dir and remove runtime modulestore to simulate an XMLModuelStore course. Set course static_asset_path and ensure we get redirected to that path
Then run the same tests as static_asset_path run. if it isn't found in the contentstore
""" """
# Simulate XMLModuleStore xmodule self.course.static_asset_path = 'dummy/static'
self.item_descriptor.data_dir = 'dummy/static' self.course.save()
del self.item_descriptor.runtime.modulestore store = modulestore()
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
self.assertFalse(self.course.static_asset_path) store.update_item(self.course, self.user.id)
# Test youtube style en # Test youtube style en
request = Request.blank('/translation/en?videoId=12345') request = Request.blank('/translation/en?videoId=12345')
......
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