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
4b5fe427
Commit
4b5fe427
authored
Jun 27, 2013
by
Peter Fogg
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #282 from edx/peter-fogg/fix-default-videos
Fix Lyla showing up everywhere.
parents
984fd2bc
ee538980
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
38 deletions
+80
-38
common/lib/xmodule/xmodule/tests/test_video_module.py
+28
-0
common/lib/xmodule/xmodule/video_module.py
+52
-38
No files found.
common/lib/xmodule/xmodule/tests/test_video_module.py
View file @
4b5fe427
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
unittest
import
unittest
from
xmodule.modulestore
import
Location
from
xmodule.video_module
import
VideoDescriptor
from
xmodule.video_module
import
VideoDescriptor
from
.test_import
import
DummySystem
from
.test_import
import
DummySystem
...
@@ -10,6 +11,33 @@ class VideoDescriptorImportTestCase(unittest.TestCase):
...
@@ -10,6 +11,33 @@ class VideoDescriptorImportTestCase(unittest.TestCase):
Make sure that VideoDescriptor can import an old XML-based video correctly.
Make sure that VideoDescriptor can import an old XML-based video correctly.
"""
"""
def
test_constructor
(
self
):
sample_xml
=
'''
<video display_name="Test Video"
youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
show_captions="false"
from="00:00:01"
to="00:01:00">
<source src="http://www.example.com/source.mp4"/>
<track src="http://www.example.com/track"/>
</video>
'''
location
=
Location
([
"i4x"
,
"edX"
,
"video"
,
"default"
,
"SampleProblem1"
])
model_data
=
{
'data'
:
sample_xml
,
'location'
:
location
}
system
=
DummySystem
(
load_error_modules
=
True
)
descriptor
=
VideoDescriptor
(
system
,
model_data
)
self
.
assertEquals
(
descriptor
.
youtube_id_0_75
,
'izygArpw-Qo'
)
self
.
assertEquals
(
descriptor
.
youtube_id_1_0
,
'p2Q6BrNhdh8'
)
self
.
assertEquals
(
descriptor
.
youtube_id_1_25
,
'1EeWXzPdhSA'
)
self
.
assertEquals
(
descriptor
.
youtube_id_1_5
,
'rABDYkeK0x8'
)
self
.
assertEquals
(
descriptor
.
show_captions
,
False
)
self
.
assertEquals
(
descriptor
.
start_time
,
1.0
)
self
.
assertEquals
(
descriptor
.
end_time
,
60
)
self
.
assertEquals
(
descriptor
.
track
,
'http://www.example.com/track'
)
self
.
assertEquals
(
descriptor
.
source
,
'http://www.example.com/source.mp4'
)
def
test_from_xml
(
self
):
def
test_from_xml
(
self
):
module_system
=
DummySystem
(
load_error_modules
=
True
)
module_system
=
DummySystem
(
load_error_modules
=
True
)
xml_data
=
'''
xml_data
=
'''
...
...
common/lib/xmodule/xmodule/video_module.py
View file @
4b5fe427
...
@@ -88,6 +88,13 @@ class VideoDescriptor(VideoFields,
...
@@ -88,6 +88,13 @@ class VideoDescriptor(VideoFields,
module_class
=
VideoModule
module_class
=
VideoModule
template_dir_name
=
"video"
template_dir_name
=
"video"
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
VideoDescriptor
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
# If we don't have a `youtube_id_1_0`, this is an XML course
# and we parse out the fields.
if
self
.
data
and
'youtube_id_1_0'
not
in
self
.
_model_data
:
_parse_video_xml
(
self
,
self
.
data
)
@property
@property
def
non_editable_metadata_fields
(
self
):
def
non_editable_metadata_fields
(
self
):
non_editable_fields
=
super
(
MetadataOnlyEditingDescriptor
,
self
)
.
non_editable_metadata_fields
non_editable_fields
=
super
(
MetadataOnlyEditingDescriptor
,
self
)
.
non_editable_metadata_fields
...
@@ -108,47 +115,54 @@ class VideoDescriptor(VideoFields,
...
@@ -108,47 +115,54 @@ class VideoDescriptor(VideoFields,
url identifiers
url identifiers
"""
"""
video
=
super
(
VideoDescriptor
,
cls
)
.
from_xml
(
xml_data
,
system
,
org
,
course
)
video
=
super
(
VideoDescriptor
,
cls
)
.
from_xml
(
xml_data
,
system
,
org
,
course
)
xml
=
etree
.
fromstring
(
xml_data
)
_parse_video_xml
(
video
,
xml_data
)
display_name
=
xml
.
get
(
'display_name'
)
if
display_name
:
video
.
display_name
=
display_name
youtube
=
xml
.
get
(
'youtube'
)
if
youtube
:
speeds
=
_parse_youtube
(
youtube
)
if
speeds
[
'0.75'
]:
video
.
youtube_id_0_75
=
speeds
[
'0.75'
]
if
speeds
[
'1.00'
]:
video
.
youtube_id_1_0
=
speeds
[
'1.00'
]
if
speeds
[
'1.25'
]:
video
.
youtube_id_1_25
=
speeds
[
'1.25'
]
if
speeds
[
'1.50'
]:
video
.
youtube_id_1_5
=
speeds
[
'1.50'
]
show_captions
=
xml
.
get
(
'show_captions'
)
if
show_captions
:
video
.
show_captions
=
json
.
loads
(
show_captions
)
source
=
_get_first_external
(
xml
,
'source'
)
if
source
:
video
.
source
=
source
track
=
_get_first_external
(
xml
,
'track'
)
if
track
:
video
.
track
=
track
start_time
=
_parse_time
(
xml
.
get
(
'from'
))
if
start_time
:
video
.
start_time
=
start_time
end_time
=
_parse_time
(
xml
.
get
(
'to'
))
if
end_time
:
video
.
end_time
=
end_time
return
video
return
video
def
_parse_video_xml
(
video
,
xml_data
):
"""
Parse video fields out of xml_data. The fields are set if they are
present in the XML.
"""
xml
=
etree
.
fromstring
(
xml_data
)
display_name
=
xml
.
get
(
'display_name'
)
if
display_name
:
video
.
display_name
=
display_name
youtube
=
xml
.
get
(
'youtube'
)
if
youtube
:
speeds
=
_parse_youtube
(
youtube
)
if
speeds
[
'0.75'
]:
video
.
youtube_id_0_75
=
speeds
[
'0.75'
]
if
speeds
[
'1.00'
]:
video
.
youtube_id_1_0
=
speeds
[
'1.00'
]
if
speeds
[
'1.25'
]:
video
.
youtube_id_1_25
=
speeds
[
'1.25'
]
if
speeds
[
'1.50'
]:
video
.
youtube_id_1_5
=
speeds
[
'1.50'
]
show_captions
=
xml
.
get
(
'show_captions'
)
if
show_captions
:
video
.
show_captions
=
json
.
loads
(
show_captions
)
source
=
_get_first_external
(
xml
,
'source'
)
if
source
:
video
.
source
=
source
track
=
_get_first_external
(
xml
,
'track'
)
if
track
:
video
.
track
=
track
start_time
=
_parse_time
(
xml
.
get
(
'from'
))
if
start_time
:
video
.
start_time
=
start_time
end_time
=
_parse_time
(
xml
.
get
(
'to'
))
if
end_time
:
video
.
end_time
=
end_time
def
_get_first_external
(
xmltree
,
tag
):
def
_get_first_external
(
xmltree
,
tag
):
"""
"""
Returns the src attribute of the nested `tag` in `xmltree`, if it
Returns the src attribute of the nested `tag` in `xmltree`, if it
...
...
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