Commit be3c29b0 by Simon Chen Committed by GitHub

Merge pull request #15550 from edx/LEARNER-683

Allow enrollment into expired seats if the api is called by ECOM service
parents 06c98269 a3d51192
...@@ -899,7 +899,12 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente ...@@ -899,7 +899,12 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
self.assert_enrollment_status(username='fake-user', expected_status=status.HTTP_406_NOT_ACCEPTABLE, self.assert_enrollment_status(username='fake-user', expected_status=status.HTTP_406_NOT_ACCEPTABLE,
as_server=True) as_server=True)
def test_update_enrollment_with_expired_mode_throws_error(self): @ddt.data(
(True, CourseMode.VERIFIED),
(False, CourseMode.DEFAULT_MODE_SLUG)
)
@ddt.unpack
def test_update_enrollment_with_expired_mode(self, using_api_key, updated_mode):
"""Verify that if verified mode is expired than it's enrollment cannot be updated. """ """Verify that if verified mode is expired than it's enrollment cannot be updated. """
for mode in [CourseMode.DEFAULT_MODE_SLUG, CourseMode.VERIFIED]: for mode in [CourseMode.DEFAULT_MODE_SLUG, CourseMode.VERIFIED]:
CourseModeFactory.create( CourseModeFactory.create(
...@@ -922,13 +927,13 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente ...@@ -922,13 +927,13 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
mode.expiration_datetime = datetime.datetime(year=1970, month=1, day=1, tzinfo=pytz.utc) mode.expiration_datetime = datetime.datetime(year=1970, month=1, day=1, tzinfo=pytz.utc)
mode.save() mode.save()
self.assert_enrollment_status( self.assert_enrollment_status(
as_server=True, as_server=using_api_key,
mode=CourseMode.VERIFIED, mode=CourseMode.VERIFIED,
expected_status=status.HTTP_400_BAD_REQUEST expected_status=status.HTTP_200_OK if using_api_key else status.HTTP_403_FORBIDDEN
) )
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.DEFAULT_MODE_SLUG) self.assertEqual(course_mode, updated_mode)
def test_enterprise_course_enrollment_invalid_consent(self): def test_enterprise_course_enrollment_invalid_consent(self):
"""Verify that the enterprise_course_consent must be a boolean. """ """Verify that the enterprise_course_consent must be a boolean. """
......
...@@ -637,7 +637,9 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn): ...@@ -637,7 +637,9 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
unicode(course_id), unicode(course_id),
mode=mode, mode=mode,
is_active=is_active, is_active=is_active,
enrollment_attributes=enrollment_attributes enrollment_attributes=enrollment_attributes,
# If we are updating enrollment by authorized api caller, we should allow expired modes
include_expired=has_api_key_permissions
) )
else: else:
# Will reactivate inactive enrollments. # Will reactivate inactive enrollments.
......
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