From a3d511926fe0fe04d237082057a676b0356bd9df Mon Sep 17 00:00:00 2001 From: Simon Chen Date: Wed, 12 Jul 2017 14:24:29 -0400 Subject: [PATCH] Allow enrollment into expired seats if the api is called by ecom service --- common/djangoapps/enrollment/tests/test_views.py | 13 +++++++++---- common/djangoapps/enrollment/views.py | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/enrollment/tests/test_views.py b/common/djangoapps/enrollment/tests/test_views.py index 83a48e0b65..eeb724756e 100644 --- a/common/djangoapps/enrollment/tests/test_views.py +++ b/common/djangoapps/enrollment/tests/test_views.py @@ -899,7 +899,12 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente self.assert_enrollment_status(username='fake-user', expected_status=status.HTTP_406_NOT_ACCEPTABLE, 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. """ for mode in [CourseMode.DEFAULT_MODE_SLUG, CourseMode.VERIFIED]: CourseModeFactory.create( @@ -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.save() self.assert_enrollment_status( - as_server=True, + as_server=using_api_key, 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) 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): """Verify that the enterprise_course_consent must be a boolean. """ diff --git a/common/djangoapps/enrollment/views.py b/common/djangoapps/enrollment/views.py index 88c3ed5d24..f57db788e5 100644 --- a/common/djangoapps/enrollment/views.py +++ b/common/djangoapps/enrollment/views.py @@ -637,7 +637,9 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn): unicode(course_id), mode=mode, 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: # Will reactivate inactive enrollments.