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
f1609800
Commit
f1609800
authored
Oct 05, 2017
by
Jesse Shapiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused generic Enterprise-related enrollment logic
parent
4fa81352
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
121 deletions
+13
-121
common/djangoapps/enrollment/tests/test_views.py
+0
-80
common/djangoapps/enrollment/views.py
+13
-41
No files found.
common/djangoapps/enrollment/tests/test_views.py
View file @
f1609800
...
...
@@ -56,7 +56,6 @@ class EnrollmentTestMixin(object):
enrollment_attributes
=
None
,
min_mongo_calls
=
0
,
max_mongo_calls
=
0
,
enterprise_course_consent
=
None
,
linked_enterprise_customer
=
None
,
):
"""
...
...
@@ -84,9 +83,6 @@ class EnrollmentTestMixin(object):
if
email_opt_in
is
not
None
:
data
[
'email_opt_in'
]
=
email_opt_in
if
enterprise_course_consent
is
not
None
:
data
[
'enterprise_course_consent'
]
=
enterprise_course_consent
if
linked_enterprise_customer
is
not
None
:
data
[
'linked_enterprise_customer'
]
=
linked_enterprise_customer
...
...
@@ -966,82 +962,6 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
self
.
assertTrue
(
is_active
)
self
.
assertEqual
(
course_mode
,
updated_mode
)
@override_settings
(
ENTERPRISE_SERVICE_WORKER_USERNAME
=
'enterprise_worker'
)
@override_settings
(
ENABLE_ENTERPRISE_INTEGRATION
=
True
)
def
test_enterprise_course_enrollment_invalid_consent
(
self
):
"""Verify that the enterprise_course_consent must be a boolean. """
UserFactory
.
create
(
username
=
'enterprise_worker'
,
email
=
self
.
EMAIL
,
password
=
self
.
PASSWORD
,
)
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
DEFAULT_MODE_SLUG
,
mode_display_name
=
CourseMode
.
DEFAULT_MODE_SLUG
,
)
self
.
assert_enrollment_status
(
expected_status
=
status
.
HTTP_400_BAD_REQUEST
,
enterprise_course_consent
=
'invalid'
,
as_server
=
True
,
)
@httpretty.activate
@override_settings
(
ENTERPRISE_SERVICE_WORKER_USERNAME
=
'enterprise_worker'
)
@override_settings
(
ENABLE_ENTERPRISE_INTEGRATION
=
True
)
def
test_enterprise_course_enrollment_api_error
(
self
):
"""Verify that enterprise service errors are handled properly. """
UserFactory
.
create
(
username
=
'enterprise_worker'
,
email
=
self
.
EMAIL
,
password
=
self
.
PASSWORD
,
)
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
DEFAULT_MODE_SLUG
,
mode_display_name
=
CourseMode
.
DEFAULT_MODE_SLUG
,
)
self
.
mock_enterprise_course_enrollment_post_api_failure
()
self
.
assert_enrollment_status
(
expected_status
=
status
.
HTTP_400_BAD_REQUEST
,
enterprise_course_consent
=
True
,
as_server
=
True
,
username
=
'enterprise_worker'
)
self
.
assertEqual
(
httpretty
.
last_request
()
.
path
,
'/enterprise/api/v1/enterprise-course-enrollment/'
,
'No request was made to the mocked enterprise-course-enrollment API'
)
@httpretty.activate
@override_settings
(
ENTERPRISE_SERVICE_WORKER_USERNAME
=
'enterprise_worker'
)
@override_settings
(
ENABLE_ENTERPRISE_INTEGRATION
=
True
)
def
test_enterprise_course_enrollment_successful
(
self
):
"""Verify that the enrollment completes when the EnterpriseCourseEnrollment creation succeeds. """
UserFactory
.
create
(
username
=
'enterprise_worker'
,
email
=
self
.
EMAIL
,
password
=
self
.
PASSWORD
,
)
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
DEFAULT_MODE_SLUG
,
mode_display_name
=
CourseMode
.
DEFAULT_MODE_SLUG
,
)
self
.
mock_enterprise_course_enrollment_post_api
(
username
=
self
.
user
.
username
,
course_id
=
unicode
(
self
.
course
.
id
))
self
.
assert_enrollment_status
(
expected_status
=
status
.
HTTP_200_OK
,
enterprise_course_consent
=
True
,
as_server
=
True
,
username
=
'enterprise_worker'
)
self
.
assertEqual
(
httpretty
.
last_request
()
.
path
,
'/enterprise/api/v1/enterprise-course-enrollment/'
,
'No request was made to the mocked enterprise-course-enrollment API'
)
@httpretty.activate
@override_settings
(
ENTERPRISE_SERVICE_WORKER_USERNAME
=
'enterprise_worker'
)
@override_settings
(
ENABLE_ENTERPRISE_INTEGRATION
=
True
)
...
...
common/djangoapps/enrollment/views.py
View file @
f1609800
...
...
@@ -595,50 +595,22 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
}
)
enterprise_course_consent
=
request
.
data
.
get
(
'enterprise_course_consent'
)
explicit_linked_enterprise
=
request
.
data
.
get
(
'linked_enterprise_customer'
)
if
(
enterprise_course_consent
or
explicit_linked_enterprise
)
and
has_api_key_permissions
and
enterprise_enabled
():
if
explicit_linked_enterprise
and
has_api_key_permissions
and
enterprise_enabled
():
enterprise_api_client
=
EnterpriseApiServiceClient
()
consent_client
=
ConsentApiServiceClient
()
# We received an explicitly-linked EnterpriseCustomer for the enrollment
if
explicit_linked_enterprise
is
not
None
:
try
:
enterprise_api_client
.
post_enterprise_course_enrollment
(
username
,
unicode
(
course_id
),
None
)
except
EnterpriseApiException
as
error
:
log
.
exception
(
"An unexpected error occurred while creating the new EnterpriseCourseEnrollment "
"for user [
%
s] in course run [
%
s]"
,
username
,
course_id
)
raise
CourseEnrollmentError
(
error
.
message
)
kwargs
=
{
'username'
:
username
,
'course_id'
:
unicode
(
course_id
),
'enterprise_customer_uuid'
:
explicit_linked_enterprise
,
}
consent_client
.
provide_consent
(
**
kwargs
)
# We received an implicit "consent granted" parameter from ecommerce
# TODO: Once ecommerce has been deployed with explicit enterprise support, remove this
# entire chunk of logic, related tests, and any supporting methods no longer required.
elif
enterprise_course_consent
is
not
None
:
# Check if the enterprise_course_enrollment is a boolean
if
not
isinstance
(
enterprise_course_consent
,
bool
):
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
,
data
=
{
'message'
:
(
u"'{value}' is an invalid enterprise course consent value."
)
.
format
(
value
=
enterprise_course_consent
)
}
)
try
:
enterprise_api_client
.
post_enterprise_course_enrollment
(
username
,
unicode
(
course_id
),
enterprise_course_consent
)
except
EnterpriseApiException
as
error
:
log
.
exception
(
"An unexpected error occurred while creating the new EnterpriseCourseEnrollment "
"for user [
%
s] in course run [
%
s]"
,
username
,
course_id
)
raise
CourseEnrollmentError
(
error
.
message
)
try
:
enterprise_api_client
.
post_enterprise_course_enrollment
(
username
,
unicode
(
course_id
),
None
)
except
EnterpriseApiException
as
error
:
log
.
exception
(
"An unexpected error occurred while creating the new EnterpriseCourseEnrollment "
"for user [
%
s] in course run [
%
s]"
,
username
,
course_id
)
raise
CourseEnrollmentError
(
error
.
message
)
kwargs
=
{
'username'
:
username
,
'course_id'
:
unicode
(
course_id
),
'enterprise_customer_uuid'
:
explicit_linked_enterprise
,
}
consent_client
.
provide_consent
(
**
kwargs
)
enrollment_attributes
=
request
.
data
.
get
(
'enrollment_attributes'
)
enrollment
=
api
.
get_enrollment
(
username
,
unicode
(
course_id
))
...
...
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