diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 99dd2fbd3c7124fe970fb139e7fcf2562987de08..46751029158ca2e0bf47e39f32dcb85063d52dc2 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -943,7 +943,10 @@ class SoftwareSecurePhotoVerification(PhotoVerification): Returns: SoftwareSecurePhotoVerification (object) or None """ - recent_verification = SoftwareSecurePhotoVerification.objects.filter(status='approved', user_id=user.id) + recent_verification = SoftwareSecurePhotoVerification.objects.filter(status='approved', + user_id=user.id, + expiry_date__isnull=False) + return recent_verification.latest('updated_at') if recent_verification.exists() else None @classmethod diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index feeca85d9b808e1db75d12594ad836fe3d705d63..a8dd45b88e24bcb417d1a98ba56df59d44a8596e 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import json -from datetime import timedelta +from datetime import datetime, timedelta import boto import ddt @@ -380,6 +380,7 @@ class TestPhotoVerification(TestVerification, MockS3Mixin, ModuleStoreTestCase): # Make an approved verification attempt = SoftwareSecurePhotoVerification(user=user) attempt.status = 'approved' + attempt.expiry_date = datetime.now() attempt.save() # Test method 'get_recent_verification' returns the most recent @@ -388,6 +389,25 @@ class TestPhotoVerification(TestVerification, MockS3Mixin, ModuleStoreTestCase): self.assertIsNotNone(recent_verification) self.assertEqual(recent_verification.id, attempt.id) + def test_get_recent_verification_expiry_null(self): + """Test that method 'get_recent_verification' of model + 'SoftwareSecurePhotoVerification' will return None when expiry_date + is NULL for 'approved' verifications based on updated_at value. + """ + user = UserFactory.create() + attempt = None + + for _ in range(2): + # Make an approved verification + attempt = SoftwareSecurePhotoVerification(user=user) + attempt.status = 'approved' + attempt.save() + + # Test method 'get_recent_verification' returns None + # as attempts don't have an expiry_date + recent_verification = SoftwareSecurePhotoVerification.get_recent_verification(user=user) + self.assertIsNone(recent_verification) + def test_no_approved_verification(self): """Test that method 'get_recent_verification' of model 'SoftwareSecurePhotoVerification' returns None if no