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
e3fe2f97
Commit
e3fe2f97
authored
Feb 17, 2017
by
Albert (AJ) St. Aubin
Committed by
GitHub
Feb 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14533 from edx/aj/TNL-6552_upgrade_cookie
update session cookie with the course id
parents
be887833
13ee3056
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
11 deletions
+49
-11
lms/djangoapps/courseware/tests/test_date_summary.py
+30
-3
lms/djangoapps/courseware/views/views.py
+19
-8
No files found.
lms/djangoapps/courseware/tests/test_date_summary.py
View file @
e3fe2f97
...
...
@@ -49,14 +49,17 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
course_min_price
=
100
,
days_till_verification_deadline
=
14
,
verification_status
=
None
,
sku
=
None
sku
=
None
,
create_user
=
True
):
"""Set up the course and user for this test."""
now
=
datetime
.
now
(
utc
)
if
create_user
:
self
.
user
=
UserFactory
.
create
(
username
=
'mrrobot'
,
password
=
'test'
)
# pylint: disable=attribute-defined-outside-init
self
.
course
=
CourseFactory
.
create
(
# pylint: disable=attribute-defined-outside-init
start
=
now
+
timedelta
(
days
=
days_till_start
)
)
self
.
user
=
UserFactory
.
create
(
username
=
'mrrobot'
,
password
=
'test'
)
# pylint: disable=attribute-defined-outside-init
if
days_till_end
is
not
None
:
self
.
course
.
end
=
now
+
timedelta
(
days
=
days_till_end
)
...
...
@@ -280,7 +283,12 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
# Tests Verified Upgrade Deadline Date Block
def
check_upgrade_banner
(
self
,
banner_expected
=
True
,
include_url_parameter
=
True
):
def
check_upgrade_banner
(
self
,
banner_expected
=
True
,
include_url_parameter
=
True
,
expected_cookie_value
=
None
):
"""
Helper method to check for the presence of the Upgrade Banner
"""
...
...
@@ -288,11 +296,17 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
if
include_url_parameter
:
url
+=
'?upgrade=true'
resp
=
self
.
client
.
get
(
url
)
upgrade_cookie_name
=
'show_upgrade_notification'
expected_banner_text
=
"Give yourself an additional incentive to complete"
if
banner_expected
:
self
.
assertIn
(
expected_banner_text
,
resp
.
content
)
self
.
assertIn
(
str
(
self
.
course
.
id
),
self
.
client
.
cookies
[
upgrade_cookie_name
]
.
value
)
else
:
self
.
assertNotIn
(
expected_banner_text
,
resp
.
content
)
if
upgrade_cookie_name
in
self
.
client
.
cookies
:
self
.
assertNotIn
(
str
(
self
.
course
.
id
),
self
.
client
.
cookies
[
upgrade_cookie_name
]
.
value
)
if
expected_cookie_value
is
not
None
:
self
.
assertIn
(
str
(
expected_cookie_value
),
self
.
client
.
cookies
[
upgrade_cookie_name
]
.
value
)
@freeze_time
(
'2015-01-02'
)
def
test_verified_upgrade_deadline_date
(
self
):
...
...
@@ -335,6 +349,19 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
# the URL parameter in order to see the notification.
self
.
check_upgrade_banner
(
include_url_parameter
=
False
)
# Store the current course_id for testing
old_course_id
=
self
.
course
.
id
# Change to another course
self
.
setup_course_and_user
(
days_till_upgrade_deadline
=
1
,
user_enrollment_mode
=
CourseMode
.
AUDIT
,
create_user
=
False
)
# Banner should not be present in the newly created course
self
.
check_upgrade_banner
(
include_url_parameter
=
False
,
banner_expected
=
False
,
expected_cookie_value
=
old_course_id
)
# Unfortunately (according to django doc), it is not possible to test expiration of the cookie.
def
test_ecommerce_checkout_redirect
(
self
):
...
...
lms/djangoapps/courseware/views/views.py
View file @
e3fe2f97
...
...
@@ -354,13 +354,16 @@ def course_info(request, course_id):
if
request
.
GET
.
get
(
'upgrade'
,
'false'
)
==
'true'
:
store_upgrade_cookie
=
True
show_upgrade_notification
=
True
elif
upgrade_cookie_name
in
request
.
COOKIES
and
bool
(
request
.
COOKIES
[
upgrade_cookie_name
])
:
elif
upgrade_cookie_name
in
request
.
COOKIES
and
course_id
in
request
.
COOKIES
[
upgrade_cookie_name
]
:
show_upgrade_notification
=
True
if
show_upgrade_notification
:
upgrade_data
=
VerifiedUpgradeDeadlineDate
(
course
,
user
)
if
upgrade_data
.
is_enabled
:
upgrade_link
=
upgrade_data
.
link
else
:
# The upgrade is not enabled so the cookie does not need to be stored
store_upgrade_cookie
=
False
context
=
{
'request'
:
request
,
...
...
@@ -393,13 +396,21 @@ def course_info(request, course_id):
response
=
render_to_response
(
'courseware/info.html'
,
context
)
if
store_upgrade_cookie
:
response
.
set_cookie
(
upgrade_cookie_name
,
True
,
max_age
=
10
*
24
*
60
*
60
,
# set for 10 days
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
httponly
=
True
# no use case for accessing from JavaScript
)
if
upgrade_cookie_name
in
request
.
COOKIES
and
str
(
course_id
)
not
in
request
.
COOKIES
[
upgrade_cookie_name
]:
cookie_value
=
'
%
s,
%
s'
%
(
course_id
,
request
.
COOKIES
[
upgrade_cookie_name
])
elif
upgrade_cookie_name
in
request
.
COOKIES
and
str
(
course_id
)
in
request
.
COOKIES
[
upgrade_cookie_name
]:
cookie_value
=
request
.
COOKIES
[
upgrade_cookie_name
]
else
:
cookie_value
=
course_id
if
cookie_value
is
not
None
:
response
.
set_cookie
(
upgrade_cookie_name
,
cookie_value
,
max_age
=
10
*
24
*
60
*
60
,
# set for 10 days
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
httponly
=
True
# no use case for accessing from JavaScript
)
return
response
...
...
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