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
373d948c
Commit
373d948c
authored
Jun 04, 2015
by
Jim Abramson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8356 from edx/jsa/xcom-388
Add tests for enrollment deactivation under various modes.
parents
32749a66
445a0c93
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
common/djangoapps/enrollment/tests/test_views.py
+28
-9
common/djangoapps/enrollment/views.py
+1
-1
No files found.
common/djangoapps/enrollment/tests/test_views.py
View file @
373d948c
...
@@ -526,24 +526,34 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase):
...
@@ -526,24 +526,34 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase):
self
.
assertTrue
(
is_active
)
self
.
assertTrue
(
is_active
)
self
.
assertEqual
(
course_mode
,
CourseMode
.
HONOR
)
self
.
assertEqual
(
course_mode
,
CourseMode
.
HONOR
)
def
test_deactivate_enrollment
(
self
):
@ddt.data
(
((
CourseMode
.
HONOR
,
),
CourseMode
.
HONOR
),
((
CourseMode
.
HONOR
,
CourseMode
.
VERIFIED
),
CourseMode
.
HONOR
),
((
CourseMode
.
HONOR
,
CourseMode
.
VERIFIED
),
CourseMode
.
VERIFIED
),
((
CourseMode
.
PROFESSIONAL
,
),
CourseMode
.
PROFESSIONAL
),
((
CourseMode
.
NO_ID_PROFESSIONAL_MODE
,
),
CourseMode
.
NO_ID_PROFESSIONAL_MODE
),
((
CourseMode
.
VERIFIED
,
CourseMode
.
CREDIT_MODE
),
CourseMode
.
VERIFIED
),
((
CourseMode
.
VERIFIED
,
CourseMode
.
CREDIT_MODE
),
CourseMode
.
CREDIT_MODE
),
)
@ddt.unpack
def
test_deactivate_enrollment
(
self
,
configured_modes
,
selected_mode
):
"""With the right API key, deactivate (i.e., unenroll from) an existing enrollment."""
"""With the right API key, deactivate (i.e., unenroll from) an existing enrollment."""
# C
reate an honor and verified mode for a course. This allows an updat
e.
# C
onfigure a set of modes for the cours
e.
for
mode
in
[
CourseMode
.
HONOR
,
CourseMode
.
VERIFIED
]
:
for
mode
in
configured_modes
:
CourseModeFactory
.
create
(
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
course_id
=
self
.
course
.
id
,
mode_slug
=
mode
,
mode_slug
=
mode
,
mode_display_name
=
mode
,
mode_display_name
=
mode
,
)
)
# Create a
'verified' enrollment
# Create a
n enrollment with the selected mode.
self
.
assert_enrollment_status
(
as_server
=
True
,
mode
=
CourseMode
.
VERIFIED
)
self
.
assert_enrollment_status
(
as_server
=
True
,
mode
=
selected_mode
)
# Check that the enrollment
is 'verified' and
active.
# Check that the enrollment
has the correct mode and is
active.
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
))
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
))
course_mode
,
is_active
=
CourseEnrollment
.
enrollment_mode_for_user
(
self
.
user
,
self
.
course
.
id
)
course_mode
,
is_active
=
CourseEnrollment
.
enrollment_mode_for_user
(
self
.
user
,
self
.
course
.
id
)
self
.
assertTrue
(
is_active
)
self
.
assertTrue
(
is_active
)
self
.
assertEqual
(
course_mode
,
CourseMode
.
VERIFIED
)
self
.
assertEqual
(
course_mode
,
selected_mode
)
# Verify that a non-Boolean enrollment status is treated as invalid.
# Verify that a non-Boolean enrollment status is treated as invalid.
self
.
assert_enrollment_status
(
self
.
assert_enrollment_status
(
...
@@ -554,10 +564,19 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase):
...
@@ -554,10 +564,19 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase):
)
)
# Verify that the enrollment has been deactivated, and that the mode is unchanged.
# Verify that the enrollment has been deactivated, and that the mode is unchanged.
self
.
assert_enrollment_activation
(
False
)
self
.
assert_enrollment_activation
(
False
,
selected_mode
)
# Verify that enrollment deactivation is idempotent.
# Verify that enrollment deactivation is idempotent.
self
.
assert_enrollment_activation
(
False
)
self
.
assert_enrollment_activation
(
False
,
selected_mode
)
# Verify that omitting the mode returns 400 for course configurations
# in which the default (honor) mode doesn't exist.
expected_status
=
status
.
HTTP_200_OK
if
CourseMode
.
HONOR
in
configured_modes
else
status
.
HTTP_400_BAD_REQUEST
self
.
assert_enrollment_status
(
as_server
=
True
,
is_active
=
False
,
expected_status
=
expected_status
,
)
def
test_change_mode_from_user
(
self
):
def
test_change_mode_from_user
(
self
):
"""Users should not be able to alter the enrollment mode on an enrollment. """
"""Users should not be able to alter the enrollment mode on an enrollment. """
...
...
common/djangoapps/enrollment/views.py
View file @
373d948c
...
@@ -425,7 +425,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
...
@@ -425,7 +425,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
response
=
api
.
update_enrollment
(
username
,
unicode
(
course_id
),
mode
=
mode
,
is_active
=
is_active
)
response
=
api
.
update_enrollment
(
username
,
unicode
(
course_id
),
mode
=
mode
,
is_active
=
is_active
)
else
:
else
:
# Will reactivate inactive enrollments.
# Will reactivate inactive enrollments.
response
=
api
.
add_enrollment
(
username
,
unicode
(
course_id
),
mode
=
mode
)
response
=
api
.
add_enrollment
(
username
,
unicode
(
course_id
),
mode
=
mode
,
is_active
=
is_active
)
email_opt_in
=
request
.
DATA
.
get
(
'email_opt_in'
,
None
)
email_opt_in
=
request
.
DATA
.
get
(
'email_opt_in'
,
None
)
if
email_opt_in
is
not
None
:
if
email_opt_in
is
not
None
:
...
...
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