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
10b33c8a
Commit
10b33c8a
authored
Nov 16, 2016
by
Adam Palay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use a QueryDict to encode a url param that potentially has unicode (ECOM-6390)
parent
062e0506
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
lms/djangoapps/courseware/tests/test_course_info.py
+30
-2
lms/djangoapps/courseware/views/views.py
+8
-4
No files found.
lms/djangoapps/courseware/tests/test_course_info.py
View file @
10b33c8a
# coding=utf-8
"""
"""
Test the course_info xblock
Test the course_info xblock
"""
"""
import
mock
import
mock
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
from
pyquery
import
PyQuery
as
pq
from
pyquery
import
PyQuery
as
pq
from
urllib
import
urlencode
from
ccx_keys.locator
import
CCXLocator
from
ccx_keys.locator
import
CCXLocator
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.http
import
QueryDict
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
openedx.core.djangoapps.self_paced.models
import
SelfPacedConfiguration
from
openedx.core.djangoapps.self_paced.models
import
SelfPacedConfiguration
...
@@ -89,7 +90,34 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase):
...
@@ -89,7 +90,34 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase):
url
=
reverse
(
'info'
,
args
=
[
unicode
(
self
.
course
.
id
)])
url
=
reverse
(
'info'
,
args
=
[
unicode
(
self
.
course
.
id
)])
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
start_date
=
strftime_localized
(
self
.
course
.
start
,
'SHORT_DATE'
)
start_date
=
strftime_localized
(
self
.
course
.
start
,
'SHORT_DATE'
)
self
.
assertRedirects
(
response
,
'{0}?{1}'
.
format
(
reverse
(
'dashboard'
),
urlencode
({
'notlive'
:
start_date
})))
expected_params
=
QueryDict
(
mutable
=
True
)
expected_params
[
'notlive'
]
=
start_date
expected_url
=
'{url}?{params}'
.
format
(
url
=
reverse
(
'dashboard'
),
params
=
expected_params
.
urlencode
()
)
self
.
assertRedirects
(
response
,
expected_url
)
@mock.patch.dict
(
settings
.
FEATURES
,
{
'DISABLE_START_DATES'
:
False
})
@mock.patch
(
"courseware.views.views.strftime_localized"
)
def
test_non_live_course_other_language
(
self
,
mock_strftime_localized
):
"""Ensure that a user accessing a non-live course sees a redirect to
the student dashboard, not a 404, even if the localized date is unicode
"""
self
.
setup_user
()
self
.
enroll
(
self
.
course
)
fake_unicode_start_time
=
u"üñîçø∂é_ßtå®t_tîµé"
mock_strftime_localized
.
return_value
=
fake_unicode_start_time
url
=
reverse
(
'info'
,
args
=
[
unicode
(
self
.
course
.
id
)])
response
=
self
.
client
.
get
(
url
)
expected_params
=
QueryDict
(
mutable
=
True
)
expected_params
[
'notlive'
]
=
fake_unicode_start_time
expected_url
=
u'{url}?{params}'
.
format
(
url
=
reverse
(
'dashboard'
),
params
=
expected_params
.
urlencode
()
)
self
.
assertRedirects
(
response
,
expected_url
)
def
test_nonexistent_course
(
self
):
def
test_nonexistent_course
(
self
):
self
.
setup_user
()
self
.
setup_user
()
...
...
lms/djangoapps/courseware/views/views.py
View file @
10b33c8a
...
@@ -17,7 +17,7 @@ from django.core.urlresolvers import reverse
...
@@ -17,7 +17,7 @@ from django.core.urlresolvers import reverse
from
django.core.context_processors
import
csrf
from
django.core.context_processors
import
csrf
from
django.db
import
transaction
from
django.db
import
transaction
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.http
import
Http404
,
HttpResponse
,
HttpResponseBadRequest
,
HttpResponseForbidden
from
django.http
import
Http404
,
HttpResponse
,
HttpResponseBadRequest
,
HttpResponseForbidden
,
QueryDict
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
django.utils.timezone
import
UTC
from
django.utils.timezone
import
UTC
...
@@ -271,7 +271,7 @@ def course_info(request, course_id):
...
@@ -271,7 +271,7 @@ def course_info(request, course_id):
Assumes the course_id is in a valid format.
Assumes the course_id is in a valid format.
"""
"""
course_key
=
SlashSeparatedCourseKey
.
from_deprecated
_string
(
course_id
)
course_key
=
CourseKey
.
from
_string
(
course_id
)
with
modulestore
()
.
bulk_operations
(
course_key
):
with
modulestore
()
.
bulk_operations
(
course_key
):
course
=
get_course_by_id
(
course_key
,
depth
=
2
)
course
=
get_course_by_id
(
course_key
,
depth
=
2
)
access_response
=
has_access
(
request
.
user
,
'load'
,
course
,
course_key
)
access_response
=
has_access
(
request
.
user
,
'load'
,
course
,
course_key
)
...
@@ -283,8 +283,12 @@ def course_info(request, course_id):
...
@@ -283,8 +283,12 @@ def course_info(request, course_id):
# redirect to the dashboard page.
# redirect to the dashboard page.
if
isinstance
(
access_response
,
StartDateError
):
if
isinstance
(
access_response
,
StartDateError
):
start_date
=
strftime_localized
(
course
.
start
,
'SHORT_DATE'
)
start_date
=
strftime_localized
(
course
.
start
,
'SHORT_DATE'
)
params
=
urllib
.
urlencode
({
'notlive'
:
start_date
})
params
=
QueryDict
(
mutable
=
True
)
return
redirect
(
'{0}?{1}'
.
format
(
reverse
(
'dashboard'
),
params
))
params
[
'notlive'
]
=
start_date
return
redirect
(
'{dashboard_url}?{params}'
.
format
(
dashboard_url
=
reverse
(
'dashboard'
),
params
=
params
.
urlencode
()
))
# Otherwise, give a 404 to avoid leaking info about access
# Otherwise, give a 404 to avoid leaking info about access
# control.
# control.
raise
Http404
(
"Course not found."
)
raise
Http404
(
"Course not found."
)
...
...
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