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
343f35b3
Commit
343f35b3
authored
Jun 08, 2015
by
Jim Abramson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #126 from edx/jsa/xcom-396
Recover from 400 on enrollment revocation when due to mode mismatch.
parents
5a6509c5
3c20e945
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
ecommerce/extensions/fulfillment/modules.py
+8
-1
ecommerce/extensions/fulfillment/tests/test_modules.py
+20
-1
No files found.
ecommerce/extensions/fulfillment/modules.py
View file @
343f35b3
...
...
@@ -216,9 +216,16 @@ class EnrollmentFulfillmentModule(BaseFulfillmentModule):
logger
.
info
(
'Successfully revoked line [
%
d].'
,
line
.
id
)
return
True
else
:
# check if the error / message are something we can recover from.
data
=
response
.
json
()
detail
=
data
.
get
(
'message'
,
'(No details provided.)'
)
logger
.
error
(
'Failed to revoke fulfillment of Line [
%
d]:
%
s'
,
line
.
id
,
detail
)
if
response
.
status_code
==
400
and
"Enrollment mode mismatch"
in
detail
:
# The user is currently enrolled in different mode than the one
# we are refunding an order for. Don't revoke that enrollment.
logger
.
info
(
'Skipping revocation for line [
%
d]:
%
s'
,
line
.
id
,
detail
)
return
True
else
:
logger
.
error
(
'Failed to revoke fulfillment of Line [
%
d]:
%
s'
,
line
.
id
,
detail
)
except
Exception
:
# pylint: disable=broad-except
logger
.
exception
(
'Failed to revoke fulfillment of Line [
%
d].'
,
line
.
id
)
...
...
ecommerce/extensions/fulfillment/tests/test_modules.py
View file @
343f35b3
...
...
@@ -111,7 +111,26 @@ class EnrollmentFulfillmentModuleTests(CourseCatalogTestMixin, FulfillmentTestMi
self
.
assertEqual
(
actual
,
expected
)
@httpretty.activate
def
test_revoke_product_api_error
(
self
):
def
test_revoke_product_expected_error
(
self
):
"""
If the Enrollment API responds with an expected error, the method should log that revocation was
bypassed, and return True.
"""
message
=
'Enrollment mode mismatch: active mode=x, requested mode=y. Won
\'
t deactivate.'
body
=
'{{"message": "{}"}}'
.
format
(
message
)
httpretty
.
register_uri
(
httpretty
.
POST
,
settings
.
ENROLLMENT_API_URL
,
status
=
400
,
body
=
body
,
content_type
=
JSON
)
line
=
self
.
order
.
lines
.
first
()
logger_name
=
'ecommerce.extensions.fulfillment.modules'
with
LogCapture
(
logger_name
)
as
l
:
self
.
assertTrue
(
EnrollmentFulfillmentModule
()
.
revoke_line
(
line
))
l
.
check
(
(
logger_name
,
'INFO'
,
'Attempting to revoke fulfillment of Line [{}]...'
.
format
(
line
.
id
)),
(
logger_name
,
'INFO'
,
'Skipping revocation for line [
%
d]:
%
s'
%
(
line
.
id
,
message
))
)
@httpretty.activate
def
test_revoke_product_unexpected_error
(
self
):
""" If the Enrollment API responds with a non-200 status, the method should log an error and return False. """
message
=
'Meh.'
body
=
'{{"message": "{}"}}'
.
format
(
message
)
...
...
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