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
6e543c14
Commit
6e543c14
authored
Oct 15, 2013
by
Jason Bau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 + pylint
parent
4c664240
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
lms/djangoapps/shoppingcart/middleware.py
+7
-4
lms/djangoapps/shoppingcart/tests/test_middleware.py
+13
-6
No files found.
lms/djangoapps/shoppingcart/middleware.py
View file @
6e543c14
...
...
@@ -8,6 +8,7 @@ navigation. We want to do this in the middleware to
from
django.conf
import
settings
import
shoppingcart
class
UserHasCartMiddleware
(
object
):
"""
Detects whether request.user has a cart and sets it as part of the request
...
...
@@ -23,9 +24,11 @@ class UserHasCartMiddleware(object):
be displayed. Anonymous users don't.
"""
request
.
display_shopping_cart
=
False
if
(
request
.
user
.
is_authenticated
()
and
# user exists
settings
.
MITX_FEATURES
.
get
(
'ENABLE_PAID_COURSE_REGISTRATION'
)
and
# settings are set
settings
.
MITX_FEATURES
.
get
(
'ENABLE_SHOPPING_CART'
)
and
shoppingcart
.
models
.
Order
.
user_cart_has_items
(
request
.
user
)):
# user's cart is non-empty
if
(
request
.
user
.
is_authenticated
()
and
# user exists
settings
.
MITX_FEATURES
.
get
(
'ENABLE_PAID_COURSE_REGISTRATION'
)
and
# settings is set
settings
.
MITX_FEATURES
.
get
(
'ENABLE_SHOPPING_CART'
)
and
# setting is set
shoppingcart
.
models
.
Order
.
user_cart_has_items
(
request
.
user
)
# user's cart is non-empty
):
request
.
display_shopping_cart
=
True
return
None
lms/djangoapps/shoppingcart/tests/test_middleware.py
View file @
6e543c14
...
...
@@ -14,14 +14,21 @@ from course_modes.models import CourseMode
from
shoppingcart.models
import
Order
,
PaidCourseRegistration
from
shoppingcart.middleware
import
UserHasCartMiddleware
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
class
UserCartMiddlewareUnitTest
(
ModuleStoreTestCase
):
"""
Unit test for shoppingcart middleware UserHasCartMiddleware
"""
def
setUp
(
self
):
self
.
user
=
UserFactory
.
create
()
self
.
request
=
Mock
()
self
.
m
w
=
UserHasCartMiddleware
()
self
.
m
iddleware
=
UserHasCartMiddleware
()
def
add_to_cart
(
self
):
"""
Adds content to self.user's cart
"""
course
=
CourseFactory
.
create
(
org
=
'MITx'
,
number
=
'999'
,
display_name
=
'Robot Super Course'
)
course_mode
=
CourseMode
(
course_id
=
course
.
id
,
mode_slug
=
"honor"
,
...
...
@@ -38,7 +45,7 @@ class UserCartMiddlewareUnitTest(ModuleStoreTestCase):
"""
self
.
add_to_cart
()
self
.
request
.
user
=
self
.
user
self
.
m
w
.
process_request
(
self
.
request
)
self
.
m
iddleware
.
process_request
(
self
.
request
)
self
.
assertFalse
(
self
.
request
.
display_shopping_cart
)
@patch.dict
(
settings
.
MITX_FEATURES
,
{
'ENABLE_SHOPPING_CART'
:
True
,
'ENABLE_PAID_COURSE_REGISTRATION'
:
False
})
...
...
@@ -48,7 +55,7 @@ class UserCartMiddlewareUnitTest(ModuleStoreTestCase):
"""
self
.
add_to_cart
()
self
.
request
.
user
=
self
.
user
self
.
m
w
.
process_request
(
self
.
request
)
self
.
m
iddleware
.
process_request
(
self
.
request
)
self
.
assertFalse
(
self
.
request
.
display_shopping_cart
)
@patch.dict
(
settings
.
MITX_FEATURES
,
{
'ENABLE_SHOPPING_CART'
:
True
,
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
...
...
@@ -57,7 +64,7 @@ class UserCartMiddlewareUnitTest(ModuleStoreTestCase):
Tests when request.user is anonymous
"""
self
.
request
.
user
=
AnonymousUser
()
self
.
m
w
.
process_request
(
self
.
request
)
self
.
m
iddleware
.
process_request
(
self
.
request
)
self
.
assertFalse
(
self
.
request
.
display_shopping_cart
)
@patch.dict
(
settings
.
MITX_FEATURES
,
{
'ENABLE_SHOPPING_CART'
:
True
,
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
...
...
@@ -66,7 +73,7 @@ class UserCartMiddlewareUnitTest(ModuleStoreTestCase):
Tests when request.user doesn't have a cart with items
"""
self
.
request
.
user
=
self
.
user
self
.
m
w
.
process_request
(
self
.
request
)
self
.
m
iddleware
.
process_request
(
self
.
request
)
self
.
assertFalse
(
self
.
request
.
display_shopping_cart
)
@patch.dict
(
settings
.
MITX_FEATURES
,
{
'ENABLE_SHOPPING_CART'
:
True
,
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
...
...
@@ -76,5 +83,5 @@ class UserCartMiddlewareUnitTest(ModuleStoreTestCase):
"""
self
.
add_to_cart
()
self
.
request
.
user
=
self
.
user
self
.
m
w
.
process_request
(
self
.
request
)
self
.
m
iddleware
.
process_request
(
self
.
request
)
self
.
assertTrue
(
self
.
request
.
display_shopping_cart
)
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