add username and email to getProgramEnrollment response (#24186)

MST-234
This commit is contained in:
Alex Wang
2020-06-16 11:57:23 -04:00
committed by GitHub
parent 25c23f446c
commit 931f0ae5f5
2 changed files with 24 additions and 9 deletions

View File

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

View File

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