feat: add source_system to enrollments (#34540)
* feat: add source_system to enrollments
This commit is contained in:
committed by
GitHub
parent
1080d139bd
commit
649631e589
@@ -355,6 +355,7 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase
|
||||
CourseMode.PROFESSIONAL, CourseMode.CREDIT_MODE} == {mode['slug'] for mode in data[0]['course_modes']}
|
||||
assert 'enterprise_course_enrollments' not in data[0]
|
||||
assert data[0]['order_number'] == ''
|
||||
assert data[0]['source_system'] == ''
|
||||
|
||||
@ddt.data(*itertools.product(['username', 'email'], [(3, 'ORD-003'), (1, 'ORD-001')]))
|
||||
@ddt.unpack
|
||||
@@ -376,6 +377,23 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase
|
||||
assert len(data) == 1
|
||||
assert data[0]['order_number'] == order_details[1]
|
||||
|
||||
def test_order_source_system_information(self):
|
||||
CourseEnrollmentAttributeFactory(
|
||||
enrollment=self.enrollment,
|
||||
namespace='order',
|
||||
name='source_system',
|
||||
value='commercetools'
|
||||
)
|
||||
url = reverse(
|
||||
'support:enrollment_list',
|
||||
kwargs={'username_or_email': self.student.username}
|
||||
)
|
||||
response = self.client.get(url)
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
assert len(data) == 1
|
||||
assert data[0]['source_system'] == 'commercetools'
|
||||
|
||||
@override_settings(FEATURES=dict(ENABLE_ENTERPRISE_INTEGRATION=True))
|
||||
@enterprise_is_enabled()
|
||||
def test_get_enrollments_enterprise_enabled(self):
|
||||
|
||||
@@ -123,6 +123,7 @@ class EnrollmentSupportListView(GenericAPIView):
|
||||
self.include_verified_mode_info(enrollment, course_key)
|
||||
# Add order number associated with the enrollment if available
|
||||
self.include_order_number(enrollment)
|
||||
self.include_source_system(enrollment)
|
||||
# Add manual enrollment history, if it exists
|
||||
enrollment['manual_enrollment'] = self.manual_enrollment_data(enrollment, course_key)
|
||||
|
||||
@@ -290,6 +291,25 @@ class EnrollmentSupportListView(GenericAPIView):
|
||||
)
|
||||
enrollment['order_number'] = order_attribute[-1] if order_attribute else ''
|
||||
|
||||
@staticmethod
|
||||
def include_source_system(enrollment):
|
||||
"""
|
||||
For a provided enrollment data dictionary, include source_system from CourseEnrollmentAttribute if available.
|
||||
|
||||
From all the attributes of a course enrollment:
|
||||
|
||||
* Filter source_system attribute namespaced under `order`
|
||||
"""
|
||||
username = enrollment['user']
|
||||
course_id = enrollment['course_id']
|
||||
enrollment_attributes = get_enrollment_attributes(username, course_id)
|
||||
source_system = ''
|
||||
for attribute in enrollment_attributes:
|
||||
if attribute['namespace'] == 'order' and attribute['name'] == 'source_system':
|
||||
source_system = attribute.get('value', '')
|
||||
break
|
||||
enrollment['source_system'] = source_system
|
||||
|
||||
@staticmethod
|
||||
def manual_enrollment_data(enrollment_data, course_key):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user