Fix refundable status for audit orders

This commit is contained in:
Matthew Piatetsky
2018-04-24 15:38:10 -04:00
parent 321a1acb04
commit 034ad193da
2 changed files with 21 additions and 1 deletions

View File

@@ -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):

View File

@@ -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