diff --git a/common/djangoapps/enrollment/tests/test_views.py b/common/djangoapps/enrollment/tests/test_views.py index 580cbd8002221abf2fffcee1c1b3978c01a3126f..3f49313c287daf5ab69a9c91f0fbdcecf90e1270 100644 --- a/common/djangoapps/enrollment/tests/test_views.py +++ b/common/djangoapps/enrollment/tests/test_views.py @@ -1019,6 +1019,23 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente self.assertEqual(enrollment.mode, mode) self.assertEqual(enrollment.attributes.get(namespace='order', name='order_number').value, order_number) + # Updating an enrollment should update attributes (for audit mode enrollments also) + order_number = 'EDX-3000' + enrollment_attributes = [{ + 'namespace': 'order', + 'name': 'order_number', + 'value': order_number, + }] + self.assert_enrollment_status( + as_server=True, + mode='audit', + enrollment_attributes=enrollment_attributes + ) + enrollment.refresh_from_db() + self.assertTrue(enrollment.is_active) + self.assertEqual(enrollment.mode, mode) + self.assertEqual(enrollment.attributes.get(namespace='order', name='order_number').value, order_number) + @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class EnrollmentEmbargoTest(EnrollmentTestMixin, UrlResetMixin, ModuleStoreTestCase): diff --git a/common/djangoapps/enrollment/views.py b/common/djangoapps/enrollment/views.py index 096b576c29e4431bae23bd47f524efe7c7e378ac..66a398c42a8311b173d7f42d2187c682bed9fa95 100644 --- a/common/djangoapps/enrollment/views.py +++ b/common/djangoapps/enrollment/views.py @@ -691,13 +691,16 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn): mode_changed = enrollment and mode is not None and enrollment['mode'] != mode active_changed = enrollment and is_active is not None and enrollment['is_active'] != is_active missing_attrs = [] + audit_with_order = False if enrollment_attributes: actual_attrs = [ u"{namespace}:{name}".format(**attr) for attr in enrollment_attributes ] missing_attrs = set(REQUIRED_ATTRIBUTES.get(mode, [])) - set(actual_attrs) - if has_api_key_permissions and (mode_changed or active_changed): + audit_with_order = mode == 'audit' and 'order:order_number' in actual_attrs + # Remove audit_with_order when no longer needed - implemented for REV-141 + if has_api_key_permissions and (mode_changed or active_changed or audit_with_order): if mode_changed and active_changed and not is_active: # if the requester wanted to deactivate but specified the wrong mode, fail # the request (on the assumption that the requester had outdated information