Commit 42a55faf by chrisndodge

Merge pull request #1714 from edx/feature/valera/videoalpha1_studio

Added videoalpha version 1 to the advanced components in studio.
parents fa6bbfb9 587ac0ec
--- ---
metadata: metadata:
display_name: default display_name: Video Alpha 1
data_dir: a_made_up_name version: 1
data: | data: |
<videoalpha youtube="0.75:JMD_ifUUfsU,1.0:OEoXaMPEzfM,1.25:AKqURZnYqpk,1.50:DYpADpL7jAY"/> <videoalpha show_captions="true" sub="name_of_file" youtube="0.75:JMD_ifUUfsU,1.0:OEoXaMPEzfM,1.25:AKqURZnYqpk,1.50:DYpADpL7jAY" >
<source src="https://s3.amazonaws.com/edx-course-videos/edx-intro/edX-FA12-cware-1_100.mp4"/>
<source src="https://s3.amazonaws.com/edx-course-videos/edx-intro/edX-FA12-cware-1_100.webm"/>
<source src="https://s3.amazonaws.com/edx-course-videos/edx-intro/edX-FA12-cware-1_100.ogv"/>
</videoalpha>
children: [] children: []
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
import json import json
import unittest import unittest
from lxml import etree
from xmodule.poll_module import PollDescriptor from xmodule.poll_module import PollDescriptor
from xmodule.conditional_module import ConditionalDescriptor from xmodule.conditional_module import ConditionalDescriptor
from xmodule.word_cloud_module import WordCloudDescriptor from xmodule.word_cloud_module import WordCloudDescriptor
from xmodule.videoalpha_module import VideoAlphaDescriptor
class PostData: class PostData:
"""Class which emulate postdata.""" """Class which emulate postdata."""
...@@ -117,3 +119,33 @@ class WordCloudModuleTest(LogicTest): ...@@ -117,3 +119,33 @@ class WordCloudModuleTest(LogicTest):
) )
self.assertEqual(100.0, sum(i['percent'] for i in response['top_words']) ) self.assertEqual(100.0, sum(i['percent'] for i in response['top_words']) )
class VideoAlphaModuleTest(LogicTest):
descriptor_class = VideoAlphaDescriptor
raw_model_data = {
'data': '<videoalpha />'
}
def test_get_timeframe_no_parameters(self):
xmltree = etree.fromstring('<videoalpha>test</videoalpha>')
output = self.xmodule._get_timeframe(xmltree)
self.assertEqual(output, ('', ''))
def test_get_timeframe_with_one_parameter(self):
xmltree = etree.fromstring(
'<videoalpha start_time="00:04:07">test</videoalpha>'
)
output = self.xmodule._get_timeframe(xmltree)
self.assertEqual(output, (247, ''))
def test_get_timeframe_with_two_parameters(self):
xmltree = etree.fromstring(
'''<videoalpha
start_time="00:04:07"
end_time="13:04:39"
>test</videoalpha>'''
)
output = self.xmodule._get_timeframe(xmltree)
self.assertEqual(output, (247, 47079))
...@@ -93,7 +93,7 @@ class VideoAlphaModule(VideoAlphaFields, XModule): ...@@ -93,7 +93,7 @@ class VideoAlphaModule(VideoAlphaFields, XModule):
return result return result
def _get_timeframe(self, xmltree): def _get_timeframe(self, xmltree):
""" Converts 'from' and 'to' parameters in video tag to seconds. """ Converts 'start_time' and 'end_time' parameters in video tag to seconds.
If there are no parameters, returns empty string. """ If there are no parameters, returns empty string. """
def parse_time(s): def parse_time(s):
...@@ -103,11 +103,13 @@ class VideoAlphaModule(VideoAlphaFields, XModule): ...@@ -103,11 +103,13 @@ class VideoAlphaModule(VideoAlphaFields, XModule):
return '' return ''
else: else:
x = time.strptime(s, '%H:%M:%S') x = time.strptime(s, '%H:%M:%S')
return datetime.timedelta(hours=x.tm_hour, return datetime.timedelta(
minutes=x.tm_min, hours=x.tm_hour,
seconds=x.tm_sec).total_seconds() minutes=x.tm_min,
seconds=x.tm_sec
).total_seconds()
return parse_time(xmltree.get('from')), parse_time(xmltree.get('to')) return parse_time(xmltree.get('start_time')), parse_time(xmltree.get('end_time'))
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
"""Handle ajax calls to this video. """Handle ajax calls to this video.
......
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