Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4e2c4f02
Commit
4e2c4f02
authored
Jun 12, 2013
by
Peter Fogg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix times not being parse from HH:MM:SS format into floats and update video module logic tests.
parent
681e96b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
27 deletions
+44
-27
common/lib/xmodule/xmodule/video_module.py
+18
-2
lms/djangoapps/courseware/tests/test_video_xml.py
+26
-25
No files found.
common/lib/xmodule/xmodule/video_module.py
View file @
4e2c4f02
...
...
@@ -6,6 +6,8 @@ import logging
from
lxml
import
etree
from
pkg_resources
import
resource_string
,
resource_listdir
import
datetime
import
time
from
django.http
import
Http404
...
...
@@ -137,10 +139,10 @@ class VideoDescriptor(VideoFields,
tag
=
_get_first_external
(
xml
,
'tag'
)
if
tag
:
video
.
tag
=
tag
start_time
=
xml
.
get
(
'from'
)
start_time
=
_parse_time
(
xml
.
get
(
'from'
)
)
if
start_time
:
video
.
start_time
=
start_time
end_time
=
xml
.
get
(
'to'
)
end_time
=
_parse_time
(
xml
.
get
(
'to'
)
)
if
end_time
:
video
.
end_time
=
end_time
return
video
...
...
@@ -177,3 +179,17 @@ def _parse_youtube(data):
# properly.
ret
[
'
%.2
f'
%
float
(
pieces
[
0
])]
=
pieces
[
1
]
return
ret
def
_parse_time
(
str_time
):
"""Converts s in '12:34:45' format to seconds. If s is
None, returns empty string"""
if
str_time
is
None
:
return
''
else
:
obj_time
=
time
.
strptime
(
str_time
,
'
%
H:
%
M:
%
S'
)
return
datetime
.
timedelta
(
hours
=
obj_time
.
tm_hour
,
minutes
=
obj_time
.
tm_min
,
seconds
=
obj_time
.
tm_sec
)
.
total_seconds
()
lms/djangoapps/courseware/tests/test_video_xml.py
View file @
4e2c4f02
...
...
@@ -18,7 +18,7 @@ import unittest
from
mock
import
Mock
from
lxml
import
etree
from
xmodule.video_module
import
VideoDescriptor
,
VideoModule
from
xmodule.video_module
import
VideoDescriptor
,
VideoModule
,
_parse_time
,
_parse_youtube
from
xmodule.modulestore
import
Location
from
xmodule.tests
import
test_system
from
xmodule.tests.test_logic
import
LogicTest
...
...
@@ -67,30 +67,31 @@ class VideoModuleLogicTest(LogicTest):
'data'
:
'<video />'
}
def
test_get_timeframe_no_parameters
(
self
):
"""Make sure that timeframe() works correctly w/o parameters"""
xmltree
=
etree
.
fromstring
(
'<video>test</video>'
)
output
=
self
.
xmodule
.
get_timeframe
(
xmltree
)
self
.
assertEqual
(
output
,
(
''
,
''
))
def
test_get_timeframe_with_one_parameter
(
self
):
"""Make sure that timeframe() works correctly with one parameter"""
xmltree
=
etree
.
fromstring
(
'<video from="00:04:07">test</video>'
)
output
=
self
.
xmodule
.
get_timeframe
(
xmltree
)
self
.
assertEqual
(
output
,
(
247
,
''
))
def
test_get_timeframe_with_two_parameters
(
self
):
"""Make sure that timeframe() works correctly with two parameters"""
xmltree
=
etree
.
fromstring
(
'''<video
from="00:04:07"
to="13:04:39"
>test</video>'''
)
output
=
self
.
xmodule
.
get_timeframe
(
xmltree
)
self
.
assertEqual
(
output
,
(
247
,
47079
))
def
test_parse_time
(
self
):
"""Ensure that times are parse correctly into seconds."""
output
=
_parse_time
(
'00:04:07'
)
self
.
assertEqual
(
output
,
247
)
def
test_parse_youtube
(
self
):
"""Test parsing old-style Youtube ID strings into a dict."""
youtube_str
=
'0.75:jNCf2gIqpeE,1.0:ZwkTiUPN0mg,1.25:rsq9auxASqI,1.50:kMyNdzVHHgg'
output
=
_parse_youtube
(
youtube_str
)
self
.
assertEqual
(
output
,
{
'0.75'
:
'jNCf2gIqpeE'
,
'1.00'
:
'ZwkTiUPN0mg'
,
'1.25'
:
'rsq9auxASqI'
,
'1.50'
:
'kMyNdzVHHgg'
})
def
test_parse_youtube_one_video
(
self
):
"""
Ensure that all keys are present and missing speeds map to the
empty string.
"""
youtube_str
=
'0.75:jNCf2gIqpeE'
output
=
_parse_youtube
(
youtube_str
)
self
.
assertEqual
(
output
,
{
'0.75'
:
'jNCf2gIqpeE'
,
'1.00'
:
''
,
'1.25'
:
''
,
'1.50'
:
''
})
class
VideoModuleUnitTest
(
unittest
.
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment