Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
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
ecommerce
Commits
0743a866
Commit
0743a866
authored
May 16, 2018
by
christopher lee
Committed by
Christopher Lee
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fix for BasketCalculate when username or is_anonymous is not in url
LEARNER-5285
parent
cae646a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
ecommerce/extensions/api/v2/tests/views/test_baskets.py
+25
-2
ecommerce/extensions/api/v2/views/baskets.py
+1
-0
No files found.
ecommerce/extensions/api/v2/tests/views/test_baskets.py
View file @
0743a866
...
@@ -572,8 +572,7 @@ class BasketCalculateViewTests(ProgramTestMixin, TestCase):
...
@@ -572,8 +572,7 @@ class BasketCalculateViewTests(ProgramTestMixin, TestCase):
"""Verify a request made with the is_anonymous parameter is cached"""
"""Verify a request made with the is_anonymous parameter is cached"""
url_with_one_sku
=
self
.
_generate_sku_url
(
self
.
products
[
0
:
1
],
username
=
None
)
url_with_one_sku
=
self
.
_generate_sku_url
(
self
.
products
[
0
:
1
],
username
=
None
)
url_with_two_skus
=
self
.
_generate_sku_url
(
self
.
products
[
0
:
2
],
username
=
None
)
url_with_two_skus
=
self
.
_generate_sku_url
(
self
.
products
[
0
:
2
],
username
=
None
)
url_with_two_skus_reversed
=
self
.
_generate_sku_url
(
url_with_two_skus_reversed
=
self
.
_generate_sku_url
([
self
.
products
[
0
],
self
.
products
[
1
]],
username
=
None
)
[
self
.
products
[
0
],
self
.
products
[
1
]],
username
=
None
)
expected
=
{
'Test Succeeded'
:
True
}
expected
=
{
'Test Succeeded'
:
True
}
mock_calculate_basket
.
return_value
=
expected
mock_calculate_basket
.
return_value
=
expected
...
@@ -628,6 +627,30 @@ class BasketCalculateViewTests(ProgramTestMixin, TestCase):
...
@@ -628,6 +627,30 @@ class BasketCalculateViewTests(ProgramTestMixin, TestCase):
self
.
assertFalse
(
mock_calculate_basket
.
called
,
msg
=
'The cache should be hit.'
)
self
.
assertFalse
(
mock_calculate_basket
.
called
,
msg
=
'The cache should be hit.'
)
self
.
assertEqual
(
response
.
data
,
expected
)
self
.
assertEqual
(
response
.
data
,
expected
)
@mock.patch
(
'ecommerce.extensions.api.v2.views.baskets.logger.warning'
)
@mock.patch
(
'ecommerce.extensions.api.v2.views.baskets.BasketCalculateView._calculate_temporary_basket'
)
@override_flag
(
'disable_calculate_temporary_basket_atomic_transaction'
,
active
=
True
)
def
test_basket_calculate_no_query_parameters
(
self
,
mock_calculate_basket
,
mock_logger
):
"""Verify a request made without query parameters uses the request user"""
expected
=
{
'Test Succeeded'
:
True
}
mock_calculate_basket
.
return_value
=
expected
url_with_one_sku_no_anon
=
self
.
_generate_sku_url
(
self
.
products
[
0
:
1
],
add_query_params
=
False
)
# Call BasketCalculate to test that we do not hit the cache
response
=
self
.
client
.
get
(
url_with_one_sku_no_anon
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
mock_calculate_basket
.
called
,
msg
=
'The cache should be missed.'
)
self
.
assertTrue
(
mock_logger
.
called
)
self
.
assertEqual
(
response
.
data
,
expected
)
mock_calculate_basket
.
reset_mock
()
# Call BasketCalculate again to test that we do not hit the cache
response
=
self
.
client
.
get
(
url_with_one_sku_no_anon
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
mock_calculate_basket
.
called
,
msg
=
'The cache should be missed.'
)
self
.
assertEqual
(
response
.
data
,
expected
)
@httpretty.activate
@httpretty.activate
@mock.patch
(
'ecommerce.extensions.api.v2.views.baskets.logger.warning'
)
@mock.patch
(
'ecommerce.extensions.api.v2.views.baskets.logger.warning'
)
@mock.patch
(
'ecommerce.extensions.api.v2.views.baskets.BasketCalculateView._calculate_temporary_basket'
)
@mock.patch
(
'ecommerce.extensions.api.v2.views.baskets.BasketCalculateView._calculate_temporary_basket'
)
...
...
ecommerce/extensions/api/v2/views/baskets.py
View file @
0743a866
...
@@ -478,6 +478,7 @@ class BasketCalculateView(generics.GenericAPIView):
...
@@ -478,6 +478,7 @@ class BasketCalculateView(generics.GenericAPIView):
logger
.
warning
(
"Request to Basket Calculate must supply either username or is_anonymous query"
logger
.
warning
(
"Request to Basket Calculate must supply either username or is_anonymous query"
" param. Requesting user=
%
s. Future versions of this API will treat this "
" param. Requesting user=
%
s. Future versions of this API will treat this "
"WARNING as an ERROR and raise an exception."
,
basket_owner
.
username
)
"WARNING as an ERROR and raise an exception."
,
basket_owner
.
username
)
requested_username
=
request
.
user
.
username
# If a username is passed in, validate that the user has staff access or is the same user.
# If a username is passed in, validate that the user has staff access or is the same user.
if
requested_username
:
if
requested_username
:
...
...
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