diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/serializers.py b/lms/djangoapps/program_enrollments/rest_api/v1/serializers.py index 9618021a6968a9dd0002949bfbadf05dbb92ce72..009585e62800ff558540fa9ada7b543f032bcd3b 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/serializers.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/serializers.py @@ -37,6 +37,8 @@ class ProgramEnrollmentSerializer(serializers.Serializer): status = serializers.CharField() account_exists = serializers.SerializerMethodField() curriculum_uuid = serializers.UUIDField() + username = serializers.SerializerMethodField() + email = serializers.SerializerMethodField() class Meta(object): model = ProgramEnrollment @@ -44,6 +46,16 @@ class ProgramEnrollmentSerializer(serializers.Serializer): def get_account_exists(self, obj): return bool(obj.user) + def get_username(self, obj): + if obj.user: + return obj.user.username + return "" + + def get_email(self, obj): + if obj.user: + return obj.user.email + return "" + class ProgramEnrollmentRequestMixin(InvalidStatusMixin, serializers.Serializer): """ diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py index dace29ab72f88d27fef712698e439557326c41f3..ea88bc4fb9df5c76f3b6a419783f6fc9ae79a70a 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py @@ -231,7 +231,10 @@ class ProgramEnrollmentsGetTests(EnrollmentsDataMixin, APITestCase): for i in range(2, 4): user_key = 'user-{}'.format(i) ProgramEnrollmentFactory.create( - program_uuid=self.program_uuid, curriculum_uuid=self.curriculum_uuid, external_user_key=user_key, + program_uuid=self.program_uuid, + curriculum_uuid=self.curriculum_uuid, + user=UserFactory.create(username='student-{}'.format(i), email='email-{}'.format(i)), + external_user_key=user_key, ) self.addCleanup(self.destroy_program_enrollments) @@ -283,19 +286,19 @@ class ProgramEnrollmentsGetTests(EnrollmentsDataMixin, APITestCase): 'results': [ { 'student_key': 'user-0', 'status': 'pending', 'account_exists': False, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "", 'email': "" }, { 'student_key': 'user-1', 'status': 'pending', 'account_exists': False, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "", 'email': "" }, { 'student_key': 'user-2', 'status': 'enrolled', 'account_exists': True, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "student-2", 'email': "email-2" }, { 'student_key': 'user-3', 'status': 'enrolled', 'account_exists': True, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "student-3", 'email': "email-3" }, ], } @@ -312,11 +315,11 @@ class ProgramEnrollmentsGetTests(EnrollmentsDataMixin, APITestCase): expected_results = [ { 'student_key': 'user-0', 'status': 'pending', 'account_exists': False, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "", 'email': "" }, { 'student_key': 'user-1', 'status': 'pending', 'account_exists': False, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "", 'email': "" }, ] assert expected_results == response.data['results'] @@ -331,11 +334,11 @@ class ProgramEnrollmentsGetTests(EnrollmentsDataMixin, APITestCase): next_expected_results = [ { 'student_key': 'user-2', 'status': 'enrolled', 'account_exists': True, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "student-2", 'email': "email-2" }, { 'student_key': 'user-3', 'status': 'enrolled', 'account_exists': True, - 'curriculum_uuid': text_type(self.curriculum_uuid), + 'curriculum_uuid': text_type(self.curriculum_uuid), 'username': "student-3", 'email': "email-3" }, ] assert next_expected_results == next_response.data['results']