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
42af66ce
Commit
42af66ce
authored
May 31, 2016
by
Matt Drayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/determine-correct-checkout: Select proper checkout workflow based on context
parent
454368bb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
16 deletions
+21
-16
lms/djangoapps/courseware/tests/test_views.py
+13
-12
lms/djangoapps/courseware/views/views.py
+8
-4
No files found.
lms/djangoapps/courseware/tests/test_views.py
View file @
42af66ce
...
@@ -450,7 +450,7 @@ class ViewsTestCase(ModuleStoreTestCase):
...
@@ -450,7 +450,7 @@ class ViewsTestCase(ModuleStoreTestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertIn
(
in_cart_span
,
response
.
content
)
self
.
assertIn
(
in_cart_span
,
response
.
content
)
def
assert_enrollment_link_present
(
self
,
is_anonymous
,
_id
=
False
):
def
assert_enrollment_link_present
(
self
,
is_anonymous
):
"""
"""
Prepare ecommerce checkout data and assert if the ecommerce link is contained in the response.
Prepare ecommerce checkout data and assert if the ecommerce link is contained in the response.
...
@@ -474,17 +474,13 @@ class ViewsTestCase(ModuleStoreTestCase):
...
@@ -474,17 +474,13 @@ class ViewsTestCase(ModuleStoreTestCase):
# Set up the edxmako middleware for this request to create the RequestContext
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request
(
request
)
mako_middleware_process_request
(
request
)
# Construct the link for each of the four possibilities:
# Generate the course about page content
# (1) shopping cart is disabled and the user is not logged in
# (2) shopping cart is disabled and the user is logged in
# (3) shopping cart is enabled and the user is not logged in
# (4) shopping cart is enabled and the user is logged in
href
=
'<a href="{}?{}" class="add-to-cart"{}'
.
format
(
checkout_page
,
'sku=TEST123'
,
' id="">'
if
_id
else
">"
)
response
=
views
.
course_about
(
request
,
unicode
(
course
.
id
))
response
=
views
.
course_about
(
request
,
unicode
(
course
.
id
))
# Construct the link according the following scenarios and verify its presence in the response:
# (1) shopping cart is enabled and the user is not logged in
# (2) shopping cart is enabled and the user is logged in
href
=
'<a href="{uri_stem}?sku={sku}" class="add-to-cart">'
.
format
(
uri_stem
=
checkout_page
,
sku
=
sku
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertIn
(
href
,
response
.
content
)
self
.
assertIn
(
href
,
response
.
content
)
...
@@ -500,8 +496,13 @@ class ViewsTestCase(ModuleStoreTestCase):
...
@@ -500,8 +496,13 @@ class ViewsTestCase(ModuleStoreTestCase):
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SHOPPING_CART'
),
'Shopping Cart not enabled in settings'
)
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SHOPPING_CART'
),
'Shopping Cart not enabled in settings'
)
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
def
test_ecommerce_checkout_shopping_cart_enabled
(
self
,
is_anonymous
):
def
test_ecommerce_checkout_shopping_cart_enabled
(
self
,
is_anonymous
):
"""
Two scenarios are being validated here -- authenticated/known user and unauthenticated/anonymous user
For a known user we expect the checkout link to point to Otto in a scenario where the CommerceConfiguration
is active and the course mode is PROFESSIONAL.
"""
if
not
is_anonymous
:
if
not
is_anonymous
:
self
.
assert_enrollment_link_present
(
is_anonymous
=
is_anonymous
,
_id
=
True
)
self
.
assert_enrollment_link_present
(
is_anonymous
=
is_anonymous
)
else
:
else
:
request
=
self
.
request_factory
.
get
(
"foo"
)
request
=
self
.
request_factory
.
get
(
"foo"
)
self
.
assertEqual
(
EcommerceService
()
.
is_enabled
(
AnonymousUser
()),
False
)
self
.
assertEqual
(
EcommerceService
()
.
is_enabled
(
AnonymousUser
()),
False
)
...
...
lms/djangoapps/courseware/views/views.py
View file @
42af66ce
...
@@ -575,14 +575,16 @@ def course_about(request, course_id):
...
@@ -575,14 +575,16 @@ def course_about(request, course_id):
# If the ecommerce checkout flow is enabled and the mode of the course is
# If the ecommerce checkout flow is enabled and the mode of the course is
# professional or no id professional, we construct links for the enrollment
# professional or no id professional, we construct links for the enrollment
# button to add the course to the ecommerce basket.
# button to add the course to the ecommerce basket.
ecomm_service
=
EcommerceService
()
ecommerce_checkout
=
ecomm_service
.
is_enabled
(
request
.
user
)
ecommerce_checkout_link
=
''
ecommerce_checkout_link
=
''
ecommerce_bulk_checkout_link
=
''
ecommerce_bulk_checkout_link
=
''
professional_mode
=
None
professional_mode
=
None
ecomm_service
=
EcommerceService
()
is_professional_mode
=
CourseMode
.
PROFESSIONAL
in
modes
or
CourseMode
.
NO_ID_PROFESSIONAL_MODE
in
modes
is_professional_mode
=
CourseMode
.
PROFESSIONAL
in
modes
or
CourseMode
.
NO_ID_PROFESSIONAL_MODE
in
modes
if
ecomm
_service
.
is_enabled
(
request
.
user
)
and
(
is_professional_mode
)
:
if
ecomm
erce_checkout
and
is_professional_mode
:
professional_mode
=
modes
.
get
(
CourseMode
.
PROFESSIONAL
,
''
)
or
\
professional_mode
=
modes
.
get
(
CourseMode
.
PROFESSIONAL
,
''
)
or
\
modes
.
get
(
CourseMode
.
NO_ID_PROFESSIONAL_MODE
,
''
)
modes
.
get
(
CourseMode
.
NO_ID_PROFESSIONAL_MODE
,
''
)
if
professional_mode
.
sku
:
ecommerce_checkout_link
=
ecomm_service
.
checkout_page_url
(
professional_mode
.
sku
)
ecommerce_checkout_link
=
ecomm_service
.
checkout_page_url
(
professional_mode
.
sku
)
if
professional_mode
.
bulk_sku
:
if
professional_mode
.
bulk_sku
:
ecommerce_bulk_checkout_link
=
ecomm_service
.
checkout_page_url
(
professional_mode
.
bulk_sku
)
ecommerce_bulk_checkout_link
=
ecomm_service
.
checkout_page_url
(
professional_mode
.
bulk_sku
)
...
@@ -593,7 +595,9 @@ def course_about(request, course_id):
...
@@ -593,7 +595,9 @@ def course_about(request, course_id):
settings
.
PAID_COURSE_REGISTRATION_CURRENCY
[
0
]
settings
.
PAID_COURSE_REGISTRATION_CURRENCY
[
0
]
)
)
course_price
=
get_cosmetic_display_price
(
course
,
registration_price
)
course_price
=
get_cosmetic_display_price
(
course
,
registration_price
)
can_add_course_to_cart
=
_is_shopping_cart_enabled
and
registration_price
# Determine which checkout workflow to use -- LMS shoppingcart or Otto basket
can_add_course_to_cart
=
_is_shopping_cart_enabled
and
registration_price
and
not
ecommerce_checkout_link
# Used to provide context to message to student if enrollment not allowed
# Used to provide context to message to student if enrollment not allowed
can_enroll
=
bool
(
has_access
(
request
.
user
,
'enroll'
,
course
))
can_enroll
=
bool
(
has_access
(
request
.
user
,
'enroll'
,
course
))
...
@@ -624,7 +628,7 @@ def course_about(request, course_id):
...
@@ -624,7 +628,7 @@ def course_about(request, course_id):
'is_cosmetic_price_enabled'
:
settings
.
FEATURES
.
get
(
'ENABLE_COSMETIC_DISPLAY_PRICE'
),
'is_cosmetic_price_enabled'
:
settings
.
FEATURES
.
get
(
'ENABLE_COSMETIC_DISPLAY_PRICE'
),
'course_price'
:
course_price
,
'course_price'
:
course_price
,
'in_cart'
:
in_cart
,
'in_cart'
:
in_cart
,
'ecommerce_checkout'
:
ecomm
_service
.
is_enabled
(
request
.
user
)
,
'ecommerce_checkout'
:
ecomm
erce_checkout
,
'ecommerce_checkout_link'
:
ecommerce_checkout_link
,
'ecommerce_checkout_link'
:
ecommerce_checkout_link
,
'ecommerce_bulk_checkout_link'
:
ecommerce_bulk_checkout_link
,
'ecommerce_bulk_checkout_link'
:
ecommerce_bulk_checkout_link
,
'professional_mode'
:
professional_mode
,
'professional_mode'
:
professional_mode
,
...
...
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