Merge pull request #2963 from louyihua/master
Fix incorrect parse of url in video_module.py
This commit is contained in:
@@ -20,7 +20,7 @@ from mock import Mock
|
||||
from . import LogicTest
|
||||
from lxml import etree
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.video_module import VideoDescriptor, create_youtube_string
|
||||
from xmodule.video_module import VideoDescriptor, create_youtube_string, get_ext
|
||||
from .test_import import DummySystem
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fields import ScopeIds
|
||||
@@ -107,6 +107,18 @@ class VideoModuleTest(LogicTest):
|
||||
'1.50': ''}
|
||||
)
|
||||
|
||||
def test_get_ext(self):
|
||||
"""Test get the file's extension in a url without query string."""
|
||||
filename_str = 'http://www.example.com/path/video.mp4'
|
||||
output = get_ext(filename_str)
|
||||
self.assertEqual(output, 'mp4')
|
||||
|
||||
def test_get_ext_with_query_string(self):
|
||||
"""Test get the file's extension in a url with query string."""
|
||||
filename_str = 'http://www.example.com/path/video.mp4?param1=1&p2=2'
|
||||
output = get_ext(filename_str)
|
||||
self.assertEqual(output, 'mp4')
|
||||
|
||||
|
||||
class VideoDescriptorTest(unittest.TestCase):
|
||||
"""Test for VideoDescriptor"""
|
||||
|
||||
@@ -43,6 +43,13 @@ from .video_utils import create_youtube_string
|
||||
|
||||
from xmodule.modulestore.inheritance import InheritanceKeyValueStore
|
||||
from xblock.runtime import KvsFieldData
|
||||
from urlparse import urlparse
|
||||
|
||||
def get_ext(filename):
|
||||
# Prevent incorrectly parsing urls like 'http://abc.com/path/video.mp4?xxxx'.
|
||||
path = urlparse(filename).path
|
||||
return path.rpartition('.')[-1]
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -259,7 +266,6 @@ class VideoModule(VideoFields, XModule):
|
||||
track_url = None
|
||||
transcript_download_format = self.transcript_download_format
|
||||
|
||||
get_ext = lambda filename: filename.rpartition('.')[-1]
|
||||
sources = {get_ext(src): src for src in self.html5_sources}
|
||||
|
||||
if self.download_video:
|
||||
|
||||
Reference in New Issue
Block a user