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
7af1ee3e
Commit
7af1ee3e
authored
Mar 20, 2015
by
Stephen Sanchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change error handling to report back internal errors.
parent
30058b91
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
11 deletions
+17
-11
lms/djangoapps/commerce/http.py
+10
-6
lms/djangoapps/commerce/tests/test_views.py
+7
-5
No files found.
lms/djangoapps/commerce/http.py
View file @
7af1ee3e
""" HTTP-related entities. """
from
rest_framework.status
import
HTTP_50
3_SERVICE_UNAVAILABLE
,
HTTP_200_OK
from
rest_framework.status
import
HTTP_50
0_INTERNAL_SERVER_ERROR
,
HTTP_200_OK
from
util.json_request
import
JsonResponse
...
...
@@ -13,9 +13,13 @@ class DetailResponse(JsonResponse):
super
(
DetailResponse
,
self
)
.
__init__
(
object
=
data
,
status
=
status
)
class
Api
ErrorResponse
(
DetailResponse
):
""" Response returned when
calls to the E-Commerce API fail or the returned data is invalid
. """
class
InternalRequest
ErrorResponse
(
DetailResponse
):
""" Response returned when
an internal service request fails
. """
def
__init__
(
self
):
message
=
'Call to E-Commerce API failed. Order creation failed.'
super
(
ApiErrorResponse
,
self
)
.
__init__
(
message
=
message
,
status
=
HTTP_503_SERVICE_UNAVAILABLE
)
def
__init__
(
self
,
internal_message
,
internal_status
):
message
=
(
'Call to E-Commerce API failed. Internal Request Status Code: '
'[{internal_status}], Internal Service Message: [{internal_message}]'
.
format
(
internal_status
=
internal_status
,
internal_message
=
internal_message
)
)
super
(
InternalRequestErrorResponse
,
self
)
.
__init__
(
message
=
message
,
status
=
HTTP_500_INTERNAL_SERVER_ERROR
)
lms/djangoapps/commerce/tests/test_views.py
View file @
7af1ee3e
...
...
@@ -48,10 +48,12 @@ class OrdersViewTests(EnrollmentEventTestMixin, EcommerceApiTestMixin, ModuleSto
actual
=
json
.
loads
(
response
.
content
)[
'detail'
]
self
.
assertEqual
(
actual
,
expected_msg
)
def
assertValidEcommerce
ApiErrorResponse
(
self
,
response
):
def
assertValidEcommerce
InternalRequestErrorResponse
(
self
,
response
,
internal_status
):
""" Asserts the response is a valid response sent when the E-Commerce API is unavailable. """
self
.
assertEqual
(
response
.
status_code
,
503
)
self
.
assertResponseMessage
(
response
,
'Call to E-Commerce API failed. Order creation failed.'
)
self
.
assertEqual
(
response
.
status_code
,
500
)
actual
=
json
.
loads
(
response
.
content
)[
'detail'
]
self
.
assertIn
(
'Call to E-Commerce API failed'
,
actual
)
self
.
assertIn
(
str
(
internal_status
),
actual
)
def
assertUserNotEnrolled
(
self
):
""" Asserts that the user is NOT enrolled in the course, and that an enrollment event was NOT fired. """
...
...
@@ -112,7 +114,7 @@ class OrdersViewTests(EnrollmentEventTestMixin, EcommerceApiTestMixin, ModuleSto
with
self
.
mock_create_order
(
side_effect
=
TimeoutError
):
response
=
self
.
_post_to_view
()
self
.
assertValidEcommerce
ApiErrorResponse
(
response
)
self
.
assertValidEcommerce
InternalRequestErrorResponse
(
response
,
408
)
self
.
assertUserNotEnrolled
()
def
test_ecommerce_api_error
(
self
):
...
...
@@ -122,7 +124,7 @@ class OrdersViewTests(EnrollmentEventTestMixin, EcommerceApiTestMixin, ModuleSto
with
self
.
mock_create_order
(
side_effect
=
ApiError
):
response
=
self
.
_post_to_view
()
self
.
assertValidEcommerce
ApiErrorResponse
(
response
)
self
.
assertValidEcommerce
InternalRequestErrorResponse
(
response
,
500
)
self
.
assertUserNotEnrolled
()
def
_test_successful_ecommerce_api_call
(
self
):
...
...
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