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
c01602f0
Commit
c01602f0
authored
Mar 23, 2015
by
Stephen Sanchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change implementation of improved logging based on new API.
parent
7af1ee3e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
11 deletions
+9
-11
lms/djangoapps/commerce/http.py
+3
-4
lms/djangoapps/commerce/tests/test_views.py
+3
-4
lms/djangoapps/commerce/views.py
+3
-3
No files found.
lms/djangoapps/commerce/http.py
View file @
c01602f0
...
...
@@ -16,10 +16,9 @@ class DetailResponse(JsonResponse):
class
InternalRequestErrorResponse
(
DetailResponse
):
""" Response returned when an internal service request fails. """
def
__init__
(
self
,
internal_message
,
internal_status
):
def
__init__
(
self
,
internal_message
):
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
)
'Call to E-Commerce API failed. Internal Service Message: [{internal_message}]'
.
format
(
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 @
c01602f0
...
...
@@ -48,12 +48,11 @@ class OrdersViewTests(EnrollmentEventTestMixin, EcommerceApiTestMixin, ModuleSto
actual
=
json
.
loads
(
response
.
content
)[
'detail'
]
self
.
assertEqual
(
actual
,
expected_msg
)
def
assertValidEcommerceInternalRequestErrorResponse
(
self
,
response
,
internal_status
):
def
assertValidEcommerceInternalRequestErrorResponse
(
self
,
response
):
""" Asserts the response is a valid response sent when the E-Commerce API is unavailable. """
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. """
...
...
@@ -114,7 +113,7 @@ class OrdersViewTests(EnrollmentEventTestMixin, EcommerceApiTestMixin, ModuleSto
with
self
.
mock_create_order
(
side_effect
=
TimeoutError
):
response
=
self
.
_post_to_view
()
self
.
assertValidEcommerceInternalRequestErrorResponse
(
response
,
408
)
self
.
assertValidEcommerceInternalRequestErrorResponse
(
response
)
self
.
assertUserNotEnrolled
()
def
test_ecommerce_api_error
(
self
):
...
...
@@ -124,7 +123,7 @@ class OrdersViewTests(EnrollmentEventTestMixin, EcommerceApiTestMixin, ModuleSto
with
self
.
mock_create_order
(
side_effect
=
ApiError
):
response
=
self
.
_post_to_view
()
self
.
assertValidEcommerceInternalRequestErrorResponse
(
response
,
500
)
self
.
assertValidEcommerceInternalRequestErrorResponse
(
response
)
self
.
assertUserNotEnrolled
()
def
_test_successful_ecommerce_api_call
(
self
):
...
...
lms/djangoapps/commerce/views.py
View file @
c01602f0
...
...
@@ -10,7 +10,7 @@ from rest_framework.views import APIView
from
commerce.api
import
EcommerceAPI
from
commerce.constants
import
OrderStatus
,
Messages
from
commerce.exceptions
import
ApiError
,
InvalidConfigurationError
from
commerce.http
import
DetailResponse
,
Api
ErrorResponse
from
commerce.http
import
DetailResponse
,
InternalRequest
ErrorResponse
from
course_modes.models
import
CourseMode
from
courseware
import
courses
from
enrollment.api
import
add_enrollment
...
...
@@ -120,6 +120,6 @@ class OrdersView(APIView):
msg
=
Messages
.
ORDER_INCOMPLETE_ENROLLED
.
format
(
order_number
=
order_number
)
return
DetailResponse
(
msg
,
status
=
HTTP_202_ACCEPTED
)
except
ApiError
:
except
ApiError
as
err
:
# The API will handle logging of the error.
return
ApiErrorResponse
(
)
return
InternalRequestErrorResponse
(
err
.
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