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
0625b84d
Commit
0625b84d
authored
Jan 12, 2015
by
Christopher Lee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6557 from edx/clee-MA-187-value-error
Clee ma 187 value error
parents
4d7c7c5f
3e5f7bac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
229 additions
and
39 deletions
+229
-39
common/test/data/split_test_module/course.xml
+1
-2
lms/djangoapps/mobile_api/video_outlines/serializers.py
+76
-27
lms/djangoapps/mobile_api/video_outlines/tests.py
+152
-10
No files found.
common/test/data/split_test_module/course.xml
View file @
0625b84d
...
@@ -16,4 +16,4 @@
...
@@ -16,4 +16,4 @@
</vertical>
</vertical>
</sequential>
</sequential>
</chapter>
</chapter>
</course>
</course>
\ No newline at end of file
lms/djangoapps/mobile_api/video_outlines/serializers.py
View file @
0625b84d
...
@@ -48,37 +48,86 @@ class BlockOutline(object):
...
@@ -48,37 +48,86 @@ class BlockOutline(object):
return
reversed
(
block_path
)
return
reversed
(
block_path
)
def
find_urls
(
block
):
def
find_urls
(
block
):
"""section and unit urls for block"""
"""
Find the section and unit urls for a block.
Returns:
unit_url, section_url:
unit_url (str): The url of a unit
section_url (str): The url of a section
"""
block_path
=
[]
block_path
=
[]
while
block
in
child_to_parent
:
while
block
in
child_to_parent
:
block
=
child_to_parent
[
block
]
block
=
child_to_parent
[
block
]
block_path
.
append
(
block
)
block_path
.
append
(
block
)
course
,
chapter
,
section
,
unit
=
list
(
reversed
(
block_path
))[:
4
]
block_list
=
list
(
reversed
(
block_path
))
position
=
1
block_count
=
len
(
block_list
)
unit_name
=
unit
.
url_name
for
block
in
section
.
children
:
chapter_id
=
block_list
[
1
]
.
location
.
block_id
if
block_count
>
1
else
None
if
block
.
name
==
unit_name
:
section
=
block_list
[
2
]
if
block_count
>
2
else
None
break
position
=
None
position
+=
1
#position is found traversing the section block
kwargs
=
dict
(
if
block_count
>
3
:
course_id
=
course
.
id
.
to_deprecated_string
(),
position
=
1
chapter
=
chapter
.
url_name
,
for
block
in
section
.
children
:
section
=
section
.
url_name
if
block
.
name
==
block_list
[
3
]
.
url_name
:
)
break
section_url
=
reverse
(
position
+=
1
"courseware_section"
,
kwargs
=
kwargs
,
if
chapter_id
is
None
:
request
=
self
.
request
,
no_chapter_url
=
reverse
(
)
"courseware"
,
kwargs
[
'position'
]
=
position
kwargs
=
dict
(
unit_url
=
reverse
(
course_id
=
unicode
(
self
.
course_id
),
"courseware_position"
,
),
kwargs
=
kwargs
,
request
=
self
.
request
request
=
self
.
request
,
)
)
return
no_chapter_url
,
no_chapter_url
return
unit_url
,
section_url
,
block_path
elif
section
is
None
:
no_section_url
=
reverse
(
"courseware_chapter"
,
kwargs
=
dict
(
course_id
=
unicode
(
self
.
course_id
),
chapter
=
chapter_id
),
request
=
self
.
request
)
return
no_section_url
,
no_section_url
elif
position
is
None
:
no_position_url
=
reverse
(
"courseware_section"
,
kwargs
=
dict
(
course_id
=
unicode
(
self
.
course_id
),
chapter
=
chapter_id
,
section
=
section
.
url_name
),
request
=
self
.
request
)
return
no_position_url
,
no_position_url
else
:
section_url
=
reverse
(
"courseware_section"
,
kwargs
=
dict
(
course_id
=
unicode
(
self
.
course_id
),
chapter
=
chapter_id
,
section
=
section
.
url_name
),
request
=
self
.
request
)
unit_url
=
reverse
(
"courseware_position"
,
kwargs
=
dict
(
course_id
=
unicode
(
self
.
course_id
),
chapter
=
chapter_id
,
section
=
section
.
url_name
,
position
=
position
),
request
=
self
.
request
)
return
unit_url
,
section_url
user
=
self
.
request
.
user
user
=
self
.
request
.
user
...
@@ -100,7 +149,7 @@ class BlockOutline(object):
...
@@ -100,7 +149,7 @@ class BlockOutline(object):
summary_fn
=
self
.
categories_to_outliner
[
curr_block
.
category
]
summary_fn
=
self
.
categories_to_outliner
[
curr_block
.
category
]
block_path
=
list
(
path
(
curr_block
))
block_path
=
list
(
path
(
curr_block
))
unit_url
,
section_url
,
_
=
find_urls
(
curr_block
)
unit_url
,
section_url
=
find_urls
(
curr_block
)
yield
{
yield
{
"path"
:
block_path
,
"path"
:
block_path
,
...
...
lms/djangoapps/mobile_api/video_outlines/tests.py
View file @
0625b84d
"""
"""
Tests for video outline API
Tests for video outline API
"""
"""
# pylint: disable=no-member
from
uuid
import
uuid4
from
uuid
import
uuid4
from
collections
import
namedtuple
from
collections
import
namedtuple
...
@@ -47,6 +48,17 @@ class TestVideoAPITestCase(MobileAPITestCase):
...
@@ -47,6 +48,17 @@ class TestVideoAPITestCase(MobileAPITestCase):
metadata
=
{
'graded'
:
True
,
'format'
:
'Homework'
},
metadata
=
{
'graded'
:
True
,
'format'
:
'Homework'
},
display_name
=
None
,
display_name
=
None
,
)
)
self
.
split_unit
=
ItemFactory
.
create
(
parent_location
=
self
.
sub_section
.
location
,
category
=
"vertical"
,
display_name
=
u"split test vertical
\u03a9
"
,
)
self
.
split_test
=
ItemFactory
.
create
(
parent_location
=
self
.
split_unit
.
location
,
category
=
"split_test"
,
display_name
=
u"split test unit"
)
self
.
edx_video_id
=
'testing-123'
self
.
edx_video_id
=
'testing-123'
...
@@ -93,16 +105,18 @@ class TestVideoAPITestCase(MobileAPITestCase):
...
@@ -93,16 +105,18 @@ class TestVideoAPITestCase(MobileAPITestCase):
Creates and returns a video with stored subtitles.
Creates and returns a video with stored subtitles.
"""
"""
subid
=
uuid4
()
.
hex
subid
=
uuid4
()
.
hex
transcripts_utils
.
save_subs_to_store
({
transcripts_utils
.
save_subs_to_store
(
'start'
:
[
100
,
200
,
240
,
390
,
1000
],
{
'end'
:
[
200
,
240
,
380
,
1000
,
1500
],
'start'
:
[
100
,
200
,
240
,
390
,
1000
],
'text'
:
[
'end'
:
[
200
,
240
,
380
,
1000
,
1500
],
'subs #1'
,
'text'
:
[
'subs #2'
,
'subs #1'
,
'subs #3'
,
'subs #2'
,
'subs #4'
,
'subs #3'
,
'subs #5'
'subs #4'
,
]},
'subs #5'
]
},
subid
,
subid
,
self
.
course
)
self
.
course
)
return
ItemFactory
.
create
(
return
ItemFactory
.
create
(
...
@@ -114,6 +128,86 @@ class TestVideoAPITestCase(MobileAPITestCase):
...
@@ -114,6 +128,86 @@ class TestVideoAPITestCase(MobileAPITestCase):
)
)
class
TestEmptyCourseVideoSummaryList
(
MobileAPITestCase
):
"""
Tests /api/mobile/v0.5/video_outlines/courses/{course_id} with no course set
"""
REVERSE_INFO
=
{
'name'
:
'video-summary-list'
,
'params'
:
[
'course_id'
]}
def
test_chapter_is_none
(
self
):
"""
Tests when there is no chapter under course, and video under course
"""
self
.
login_and_enroll
()
ItemFactory
.
create
(
parent_location
=
self
.
course
.
location
,
category
=
"video"
,
display_name
=
u"test factory video omega
\u03a9
"
,
)
course_outline
=
self
.
api_response
()
.
data
self
.
assertEqual
(
len
(
course_outline
),
1
)
section_url
=
course_outline
[
0
][
"section_url"
]
unit_url
=
course_outline
[
0
][
"unit_url"
]
self
.
assertRegexpMatches
(
section_url
,
r'courseware$'
)
self
.
assertTrue
(
section_url
)
self
.
assertTrue
(
unit_url
)
self
.
assertEqual
(
section_url
,
unit_url
)
def
test_section_is_none
(
self
):
"""
Tests when there is no section under chapter, and video under chapter
"""
self
.
login_and_enroll
()
self
.
chapter
=
ItemFactory
.
create
(
# pylint:disable=W0201
parent_location
=
self
.
course
.
location
,
category
=
"chapter"
,
display_name
=
u"test factory chapter omega
\u03a9
"
,
)
ItemFactory
.
create
(
parent_location
=
self
.
chapter
.
location
,
category
=
"video"
,
display_name
=
u"test factory video omega
\u03a9
"
,
)
course_outline
=
self
.
api_response
()
.
data
self
.
assertEqual
(
len
(
course_outline
),
1
)
section_url
=
course_outline
[
0
][
"section_url"
]
unit_url
=
course_outline
[
0
][
"unit_url"
]
self
.
assertRegexpMatches
(
section_url
,
r'courseware/test_factory_chapter_omega_
%
CE
%
A9/$'
)
self
.
assertTrue
(
section_url
)
self
.
assertTrue
(
unit_url
)
self
.
assertEqual
(
section_url
,
unit_url
)
def
test_section_under_course
(
self
):
"""
Tests when chapter is none, and video under section under course
"""
self
.
login_and_enroll
()
self
.
section
=
ItemFactory
.
create
(
# pylint:disable=W0201
parent_location
=
self
.
course
.
location
,
category
=
"sequential"
,
display_name
=
u"test factory section omega
\u03a9
"
,
)
ItemFactory
.
create
(
parent_location
=
self
.
section
.
location
,
category
=
"video"
,
display_name
=
u"test factory video omega
\u03a9
"
,
)
course_outline
=
self
.
api_response
()
.
data
self
.
assertEqual
(
len
(
course_outline
),
1
)
section_url
=
course_outline
[
0
][
"section_url"
]
unit_url
=
course_outline
[
0
][
"unit_url"
]
self
.
assertRegexpMatches
(
section_url
,
r'courseware/test_factory_section_omega_
%
CE
%
A9/$'
)
self
.
assertTrue
(
section_url
)
self
.
assertTrue
(
unit_url
)
self
.
assertEqual
(
section_url
,
unit_url
)
class
TestVideoSummaryList
(
TestVideoAPITestCase
,
MobileAuthTestMixin
,
MobileEnrolledCourseAccessTestMixin
):
class
TestVideoSummaryList
(
TestVideoAPITestCase
,
MobileAuthTestMixin
,
MobileEnrolledCourseAccessTestMixin
):
"""
"""
Tests for /api/mobile/v0.5/video_outlines/courses/{course_id}..
Tests for /api/mobile/v0.5/video_outlines/courses/{course_id}..
...
@@ -172,6 +266,54 @@ class TestVideoSummaryList(TestVideoAPITestCase, MobileAuthTestMixin, MobileEnro
...
@@ -172,6 +266,54 @@ class TestVideoSummaryList(TestVideoAPITestCase, MobileAuthTestMixin, MobileEnro
self
.
assertEqual
(
len
(
course_outline
),
1
)
self
.
assertEqual
(
len
(
course_outline
),
1
)
self
.
assertEqual
(
course_outline
[
0
][
'path'
][
2
][
'name'
],
self
.
nameless_unit
.
location
.
block_id
)
self
.
assertEqual
(
course_outline
[
0
][
'path'
][
2
][
'name'
],
self
.
nameless_unit
.
location
.
block_id
)
def
test_with_video_in_sub_section
(
self
):
"""
Tests a non standard xml format where a video is underneath a sequential
We are expecting to return the same unit and section url since there is
no unit vertical.
"""
self
.
login_and_enroll
()
ItemFactory
.
create
(
parent_location
=
self
.
sub_section
.
location
,
category
=
"video"
,
edx_video_id
=
self
.
edx_video_id
,
display_name
=
u"video in the sub section"
)
course_outline
=
self
.
api_response
()
.
data
self
.
assertEqual
(
len
(
course_outline
),
1
)
self
.
assertEqual
(
len
(
course_outline
[
0
][
'path'
]),
2
)
section_url
=
course_outline
[
0
][
"section_url"
]
unit_url
=
course_outline
[
0
][
"unit_url"
]
self
.
assertIn
(
u'courseware/test_factory_section_omega_
%
CE
%
A9/test_subsection_omega_
%
CE
%
A9'
,
section_url
)
self
.
assertTrue
(
section_url
)
self
.
assertTrue
(
unit_url
)
self
.
assertEqual
(
section_url
,
unit_url
)
def
test_with_split_test
(
self
):
self
.
login_and_enroll
()
ItemFactory
.
create
(
parent_location
=
self
.
split_test
.
location
,
category
=
"video"
,
display_name
=
u"split test video a"
,
)
ItemFactory
.
create
(
parent_location
=
self
.
split_test
.
location
,
category
=
"video"
,
display_name
=
u"split test video b"
,
)
course_outline
=
self
.
api_response
()
.
data
self
.
assertEqual
(
len
(
course_outline
),
2
)
self
.
assertEqual
(
len
(
course_outline
[
0
][
"path"
]),
4
)
self
.
assertEqual
(
len
(
course_outline
[
1
][
"path"
]),
4
)
self
.
assertEqual
(
course_outline
[
0
][
"summary"
][
"name"
],
u"split test video a"
)
self
.
assertEqual
(
course_outline
[
1
][
"summary"
][
"name"
],
u"split test video b"
)
def
test_with_hidden_blocks
(
self
):
def
test_with_hidden_blocks
(
self
):
self
.
login_and_enroll
()
self
.
login_and_enroll
()
hidden_subsection
=
ItemFactory
.
create
(
hidden_subsection
=
ItemFactory
.
create
(
...
...
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