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
d6feff0a
Commit
d6feff0a
authored
Dec 14, 2017
by
Albert St. Aubin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor fixes and code changes to the Entitlement Refund API
[LEARNER-2668]
parent
8c205ad8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletions
+54
-1
common/djangoapps/entitlements/api/v1/tests/test_views.py
+48
-0
common/djangoapps/entitlements/api/v1/views.py
+6
-1
No files found.
common/djangoapps/entitlements/api/v1/tests/test_views.py
View file @
d6feff0a
...
...
@@ -475,3 +475,51 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
assert
not
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
assert
course_entitlement
.
enrollment_course_run
is
None
assert
course_entitlement
.
expired_at
is
not
None
@patch
(
'entitlements.api.v1.views.CourseEntitlement.is_entitlement_refundable'
,
return_value
=
False
)
@patch
(
'lms.djangoapps.commerce.signals.refund_entitlement'
,
return_value
=
[
1
])
@patch
(
"entitlements.api.v1.views.get_course_runs_for_course"
)
def
test_user_can_revoke_and_no_refund_available
(
self
,
mock_get_course_runs
,
mock_refund_entitlement
,
mock_is_refundable
):
course_entitlement
=
CourseEntitlementFactory
.
create
(
user
=
self
.
user
)
mock_get_course_runs
.
return_value
=
self
.
return_values
url
=
reverse
(
self
.
ENTITLEMENTS_ENROLLMENT_NAMESPACE
,
args
=
[
str
(
course_entitlement
.
uuid
)]
)
assert
course_entitlement
.
enrollment_course_run
is
None
data
=
{
'course_run_id'
:
str
(
self
.
course
.
id
)
}
response
=
self
.
client
.
post
(
url
,
data
=
json
.
dumps
(
data
),
content_type
=
'application/json'
,
)
course_entitlement
.
refresh_from_db
()
assert
response
.
status_code
==
201
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
# Unenroll with Revoke for refund
with
patch
(
'lms.djangoapps.commerce.signals.handle_refund_entitlement'
)
as
mock_refund_handler
:
REFUND_ENTITLEMENT
.
connect
(
mock_refund_handler
)
revoke_url
=
url
+
'?is_refund=true'
response
=
self
.
client
.
delete
(
revoke_url
,
content_type
=
'application/json'
,
)
assert
response
.
status_code
==
400
course_entitlement
.
refresh_from_db
()
assert
not
mock_refund_handler
.
called
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
assert
course_entitlement
.
enrollment_course_run
is
not
None
assert
course_entitlement
.
expired_at
is
None
common/djangoapps/entitlements/api/v1/views.py
View file @
d6feff0a
...
...
@@ -262,7 +262,7 @@ class EntitlementEnrollmentViewSet(viewsets.GenericViewSet):
If is_refund parameter is provided then unenroll the user, set Entitlement expiration, and issue
a refund
"""
is_refund
=
True
if
request
.
query_params
.
get
(
'is_refund'
,
'false'
)
==
'true'
else
False
is_refund
=
request
.
query_params
.
get
(
'is_refund'
,
'false'
)
==
'true'
# Retrieve the entitlement for the UUID belongs to the current user.
try
:
...
...
@@ -310,5 +310,10 @@ class EntitlementEnrollmentViewSet(viewsets.GenericViewSet):
'Entitlement Refund failed for Course Entitlement [
%
s]. Entitlement is not refundable'
,
str
(
entitlement
.
uuid
)
)
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
,
data
=
{
'message'
:
'Entitlement refund failed, Entitlement is not refundable'
})
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
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