From b0232712648a2fc284c8dcd052c70c723b1c549a Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 28 Aug 2024 11:55:25 -0300 Subject: [PATCH] feat: Adding IDV Status to VerifiedName --- edx_name_affirmation/serializers.py | 18 +++++++++++++++++- edx_name_affirmation/tests/test_views.py | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/edx_name_affirmation/serializers.py b/edx_name_affirmation/serializers.py index b67bc88..8ca7b20 100644 --- a/edx_name_affirmation/serializers.py +++ b/edx_name_affirmation/serializers.py @@ -19,9 +19,25 @@ class VerifiedNameSerializer(serializers.ModelSerializer): verified_name = serializers.CharField(required=True) profile_name = serializers.CharField(required=True) verification_attempt_id = serializers.IntegerField(required=False, allow_null=True) + verification_attempt_status = serializers.SerializerMethodField('get_verification_attempt_status') proctored_exam_attempt_id = serializers.IntegerField(required=False, allow_null=True) status = serializers.CharField(required=False, allow_null=True) + def get_verification_attempt_status(self, obj): + try: + from lms.djangoapps.verify_student.services import IDVerificationService # pylint: disable=import-error,import-outside-toplevel + except ImportError: + return None + + idv_attempt_id = obj.verification_attempt_id + + if not idv_attempt_id: + return None + + verification = IDVerificationService.get_verification_details_by_id(idv_attempt_id) + + return verification.status if verification else None + class Meta: """ Meta Class @@ -30,7 +46,7 @@ class Meta: fields = ( "id", "created", "username", "verified_name", "profile_name", "verification_attempt_id", - "proctored_exam_attempt_id", "status" + "verification_attempt_status", "proctored_exam_attempt_id", "status" ) def validate_verified_name(self, verified_name): diff --git a/edx_name_affirmation/tests/test_views.py b/edx_name_affirmation/tests/test_views.py index 650643d..827a5dc 100644 --- a/edx_name_affirmation/tests/test_views.py +++ b/edx_name_affirmation/tests/test_views.py @@ -114,6 +114,7 @@ def test_post_200(self): 'profile_name': self.PROFILE_NAME, 'verified_name': self.VERIFIED_NAME, 'verification_attempt_id': self.ATTEMPT_ID, + 'verification_attempt_status': None, } response = self.client.post( reverse('edx_name_affirmation:verified_name'), @@ -136,7 +137,9 @@ def test_post_200_if_staff(self): 'profile_name': self.PROFILE_NAME, 'verified_name': self.VERIFIED_NAME, 'proctored_exam_attempt_id': self.ATTEMPT_ID, + 'verification_attempt_status': None, 'status': VerifiedNameStatus.APPROVED.value, + } response = self.client.post( reverse('edx_name_affirmation:verified_name'), @@ -156,6 +159,7 @@ def test_post_403_non_staff(self): 'profile_name': self.PROFILE_NAME, 'verified_name': self.VERIFIED_NAME, 'verification_attempt_id': self.ATTEMPT_ID, + 'verification_attempt_status': None, 'status': VerifiedNameStatus.APPROVED.value, } response = self.client.post( @@ -171,6 +175,7 @@ def test_post_400_invalid_name(self, verified_name): 'profile_name': self.PROFILE_NAME, 'verified_name': verified_name, 'verification_attempt_id': self.ATTEMPT_ID, + 'verification_attempt_status': None, 'status': VerifiedNameStatus.SUBMITTED.value, } response = self.client.post( @@ -185,6 +190,7 @@ def test_post_400_invalid_serializer(self): 'profile_name': self.PROFILE_NAME, 'verified_name': self.VERIFIED_NAME, 'verification_attempt_id': 'xxyz', + 'verification_attempt_status': None, 'status': VerifiedNameStatus.APPROVED.value, } response = self.client.post( @@ -357,6 +363,7 @@ def _get_expected_data( 'verified_name': verified_name_obj.verified_name, 'profile_name': verified_name_obj.profile_name, 'verification_attempt_id': verified_name_obj.verification_attempt_id, + 'verification_attempt_status': None, 'proctored_exam_attempt_id': verified_name_obj.proctored_exam_attempt_id, 'status': verified_name_obj.status, 'use_verified_name_for_certs': use_verified_name_for_certs,