Fix the url processing error when there is a query string inside the video source's url
1. In video_module.py, rewrite the get_ext() function to use the built-in urlparse module to parse the input filename first and then get the file's extension name from the parsed path. 2. In test_video.py, add two test cases (one with query string while the other without) in order to test the rewritten get_ext() function.
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"""
|
||||
|
||||
@@ -45,6 +45,12 @@ 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__)
|
||||
|
||||
|
||||
@@ -254,8 +260,6 @@ class VideoModule(VideoFields, XModule):
|
||||
track_url = None
|
||||
transcript_download_format = self.transcript_download_format
|
||||
|
||||
# Prevent incorrectly parsing urls like 'http://abc.com/path/video.mp4?xxxx'.
|
||||
get_ext = lambda filename: urlparse(filename).path.rpartition('.')[-1]
|
||||
sources = {get_ext(src): src for src in self.html5_sources}
|
||||
|
||||
if self.download_video:
|
||||
|
||||
Reference in New Issue
Block a user