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
17b8dfa9
Commit
17b8dfa9
authored
May 24, 2016
by
Kevin Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed courseware/views/index.py to fix negative vertical positions
TNL-4408
parent
35524573
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
4 deletions
+67
-4
lms/djangoapps/courseware/tests/test_views.py
+63
-0
lms/djangoapps/courseware/views/index.py
+4
-4
No files found.
lms/djangoapps/courseware/tests/test_views.py
View file @
17b8dfa9
...
...
@@ -1721,6 +1721,69 @@ class TestIndexView(ModuleStoreTestCase):
self
.
assertIn
(
"Activate Block ID: test_block_id"
,
response
.
content
)
@ddt.ddt
class
TestIndewViewWithVerticalPositions
(
ModuleStoreTestCase
):
"""
Test the index view to handle vertical positions. Confirms that first position is loaded
if input position is non-positive or greater than number of positions available.
"""
def
setUp
(
self
):
"""
Set up initial test data
"""
super
(
TestIndewViewWithVerticalPositions
,
self
)
.
setUp
()
self
.
user
=
UserFactory
()
# create course with 3 positions
self
.
course
=
CourseFactory
.
create
()
self
.
chapter
=
ItemFactory
.
create
(
parent
=
self
.
course
,
category
=
'chapter'
)
self
.
section
=
ItemFactory
.
create
(
parent
=
self
.
chapter
,
category
=
'sequential'
,
display_name
=
"Sequence"
)
ItemFactory
.
create
(
parent
=
self
.
section
,
category
=
'vertical'
,
display_name
=
"Vertical1"
)
ItemFactory
.
create
(
parent
=
self
.
section
,
category
=
'vertical'
,
display_name
=
"Vertical2"
)
ItemFactory
.
create
(
parent
=
self
.
section
,
category
=
'vertical'
,
display_name
=
"Vertical3"
)
self
.
client
.
login
(
username
=
self
.
user
,
password
=
'test'
)
CourseEnrollmentFactory
(
user
=
self
.
user
,
course_id
=
self
.
course
.
id
)
def
_get_course_vertical_by_position
(
self
,
input_position
):
"""
Returns client response to input position.
"""
return
self
.
client
.
get
(
reverse
(
'courseware_position'
,
kwargs
=
{
'course_id'
:
unicode
(
self
.
course
.
id
),
'chapter'
:
self
.
chapter
.
url_name
,
'section'
:
self
.
section
.
url_name
,
'position'
:
input_position
,
}
)
)
def
_assert_correct_position
(
self
,
response
,
expected_position
):
"""
Asserts that the expected position and the position in the response are the same
"""
self
.
assertIn
(
'data-position="{}"'
.
format
(
expected_position
),
response
.
content
)
@ddt.data
((
"-1"
,
1
),
(
"0"
,
1
),
(
"-0"
,
1
),
(
"2"
,
2
),
(
"5"
,
1
))
@ddt.unpack
def
test_vertical_positions
(
self
,
input_position
,
expected_position
):
"""
Tests the following cases:
* Load first position when negative position inputted.
* Load first position when 0/-0 position inputted.
* Load given position when 0 < input_position <= num_positions_available.
* Load first position when positive position > num_positions_available.
"""
resp
=
self
.
_get_course_vertical_by_position
(
input_position
)
self
.
_assert_correct_position
(
resp
,
expected_position
)
class
TestIndexViewWithGating
(
ModuleStoreTestCase
,
MilestonesTestCaseMixin
):
"""
Test the index view for a course with gated content
...
...
lms/djangoapps/courseware/views/index.py
View file @
17b8dfa9
...
...
@@ -97,7 +97,7 @@ class CoursewareIndex(View):
try
:
self
.
_init_new_relic
()
self
.
_
verify
_position
()
self
.
_
clean
_position
()
with
modulestore
()
.
bulk_operations
(
self
.
course_key
):
self
.
course
=
get_course_with_access
(
request
.
user
,
'load'
,
self
.
course_key
,
depth
=
CONTENT_DEPTH
)
self
.
is_staff
=
has_access
(
request
.
user
,
'staff'
,
self
.
course
)
...
...
@@ -177,13 +177,13 @@ class CoursewareIndex(View):
newrelic
.
agent
.
add_custom_parameter
(
'course_id'
,
unicode
(
self
.
course_key
))
newrelic
.
agent
.
add_custom_parameter
(
'org'
,
unicode
(
self
.
course_key
.
org
))
def
_
verify
_position
(
self
):
def
_
clean
_position
(
self
):
"""
Verify that the given position is
in fact an int
.
Verify that the given position is
an integer. If it is not positive, set it to 1
.
"""
if
self
.
position
is
not
None
:
try
:
int
(
self
.
position
)
self
.
position
=
max
(
int
(
self
.
position
),
1
)
except
ValueError
:
raise
Http404
(
u"Position {} is not an integer!"
.
format
(
self
.
position
))
...
...
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