Commit 373d948c by Jim Abramson

Merge pull request #8356 from edx/jsa/xcom-388

Add tests for enrollment deactivation under various modes.
parents 32749a66 445a0c93
...@@ -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."""
# Create an honor and verified mode for a course. This allows an update. # Configure a set of modes for the course.
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 an 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. """
......
...@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment