Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
10b33c8a
Commit
10b33c8a
authored
8 years ago
by
Adam Palay
Browse files
Options
Downloads
Patches
Plain Diff
use a QueryDict to encode a url param that potentially has unicode (ECOM-6390)
parent
062e0506
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/courseware/tests/test_course_info.py
+30
-2
30 additions, 2 deletions
lms/djangoapps/courseware/tests/test_course_info.py
lms/djangoapps/courseware/views/views.py
+8
-4
8 additions, 4 deletions
lms/djangoapps/courseware/views/views.py
with
38 additions
and
6 deletions
lms/djangoapps/courseware/tests/test_course_info.py
+
30
−
2
View file @
10b33c8a
# coding=utf-8
"""
Test the course_info xblock
"""
import
mock
from
nose.plugins.attrib
import
attr
from
pyquery
import
PyQuery
as
pq
from
urllib
import
urlencode
from
ccx_keys.locator
import
CCXLocator
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.http
import
QueryDict
from
django.test.utils
import
override_settings
from
openedx.core.djangoapps.self_paced.models
import
SelfPacedConfiguration
...
...
@@ -89,7 +90,34 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase):
url
=
reverse
(
'
info
'
,
args
=
[
unicode
(
self
.
course
.
id
)])
response
=
self
.
client
.
get
(
url
)
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
):
self
.
setup_user
()
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/courseware/views/views.py
+
8
−
4
View file @
10b33c8a
...
...
@@ -17,7 +17,7 @@ from django.core.urlresolvers import reverse
from
django.core.context_processors
import
csrf
from
django.db
import
transaction
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.utils.decorators
import
method_decorator
from
django.utils.timezone
import
UTC
...
...
@@ -271,7 +271,7 @@ def course_info(request, course_id):
Assumes the course_id is in a valid format.
"""
course_key
=
SlashSeparated
CourseKey
.
from_
deprecated_
string
(
course_id
)
course_key
=
CourseKey
.
from_string
(
course_id
)
with
modulestore
().
bulk_operations
(
course_key
):
course
=
get_course_by_id
(
course_key
,
depth
=
2
)
access_response
=
has_access
(
request
.
user
,
'
load
'
,
course
,
course_key
)
...
...
@@ -283,8 +283,12 @@ def course_info(request, course_id):
# redirect to the dashboard page.
if
isinstance
(
access_response
,
StartDateError
):
start_date
=
strftime_localized
(
course
.
start
,
'
SHORT_DATE
'
)
params
=
urllib
.
urlencode
({
'
notlive
'
:
start_date
})
return
redirect
(
'
{0}?{1}
'
.
format
(
reverse
(
'
dashboard
'
),
params
))
params
=
QueryDict
(
mutable
=
True
)
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
# control.
raise
Http404
(
"
Course not found.
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment