Skip to content

Commit

Permalink
fix: Moved attempt status getter from Serialized to Model
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Aug 30, 2024
1 parent b023271 commit ecec71e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
14 changes: 14 additions & 0 deletions edx_name_affirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ class Meta:
db_table = 'nameaffirmation_verifiedname'
verbose_name = 'verified name'

@property
def verification_attempt_status(self):
if not self.verification_attempt_id:
return None

try:
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
except ImportError:
return None

verification = SoftwareSecurePhotoVerification.objects.get(id=self.verification_attempt_id)

return verification.status if verification else None


class VerifiedNameConfig(ConfigurationModel):
"""
Expand Down
17 changes: 1 addition & 16 deletions edx_name_affirmation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@ 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')
verification_attempt_status = serializers.CharField(required=False, allow_null=True)
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
Expand Down
5 changes: 5 additions & 0 deletions edx_name_affirmation/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from edx_name_affirmation.models import VerifiedName
from edx_name_affirmation.statuses import VerifiedNameStatus

try:
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
except ImportError:
pass

User = get_user_model()


Expand Down
1 change: 0 additions & 1 deletion edx_name_affirmation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def test_post_200_if_staff(self):
'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'),
Expand Down

0 comments on commit ecec71e

Please sign in to comment.