Commit c78b1be5 by zubair-arbi Committed by Calen Pennington

add new column 'copy_id_photo_from' for 'SoftwareSecurePhotoVerification' model…

add new column 'copy_id_photo_from' for 'SoftwareSecurePhotoVerification' model to track initial verification with 'photo_id_key'
parent 882c2fa3
...@@ -588,16 +588,23 @@ class SoftwareSecurePhotoVerification(PhotoVerification): ...@@ -588,16 +588,23 @@ class SoftwareSecurePhotoVerification(PhotoVerification):
photo_id_key = models.TextField(max_length=1024) photo_id_key = models.TextField(max_length=1024)
IMAGE_LINK_DURATION = 5 * 60 * 60 * 24 # 5 days in seconds IMAGE_LINK_DURATION = 5 * 60 * 60 * 24 # 5 days in seconds
copy_id_photo_from = models.ForeignKey("self", null=True, blank=True)
@classmethod @classmethod
def get_initial_verification(cls, user): def get_initial_verification(cls, user):
"""Get initial verification for a user """Get initial verification for a user with the 'photo_id_key'.
Arguments: Arguments:
user(User): user object user(User): user object
Return: Return:
SoftwareSecurePhotoVerification (object) SoftwareSecurePhotoVerification (object)
""" """
init_verification = cls.objects.filter(user=user, status__in=["submitted", "approved"]) init_verification = cls.objects.filter(
user=user,
status__in=["submitted", "approved"]
).exclude(photo_id_key='')
return init_verification.latest('created_at') if init_verification.exists() else None return init_verification.latest('created_at') if init_verification.exists() else None
@status_before_must_be("created") @status_before_must_be("created")
......
...@@ -472,6 +472,38 @@ class TestPhotoVerification(ModuleStoreTestCase): ...@@ -472,6 +472,38 @@ class TestPhotoVerification(ModuleStoreTestCase):
status = SoftwareSecurePhotoVerification.verification_status_for_user(user, course.id, enrollment_mode) status = SoftwareSecurePhotoVerification.verification_status_for_user(user, course.id, enrollment_mode)
self.assertEqual(status, output) self.assertEqual(status, output)
def test_initial_verification_for_user(self):
"""Test that method 'get_initial_verification' of model
'SoftwareSecurePhotoVerification' always returns the initial
verification with field 'photo_id_key' set against a user.
"""
user = UserFactory.create()
# No initial verification for the user
result = SoftwareSecurePhotoVerification.get_initial_verification(user=user)
self.assertIs(result, None)
# Make an initial verification with 'photo_id_key'
attempt = SoftwareSecurePhotoVerification(user=user, photo_id_key="dummy_photo_id_key")
attempt.status = 'approved'
attempt.save()
# Check that method 'get_initial_verification' returns the correct
# initial verification attempt
first_result = SoftwareSecurePhotoVerification.get_initial_verification(user=user)
self.assertIsNotNone(first_result)
# Now create a second verification without 'photo_id_key'
attempt = SoftwareSecurePhotoVerification(user=user)
attempt.status = 'submitted'
attempt.save()
# Test method 'get_initial_verification' still returns the correct
# initial verification attempt which have 'photo_id_key' set
second_result = SoftwareSecurePhotoVerification.get_initial_verification(user=user)
self.assertIsNotNone(second_result)
self.assertEqual(second_result, first_result)
@ddt.ddt @ddt.ddt
class VerificationCheckpointTest(ModuleStoreTestCase): class VerificationCheckpointTest(ModuleStoreTestCase):
......
...@@ -1420,11 +1420,15 @@ class TestSubmitPhotosForVerification(TestCase): ...@@ -1420,11 +1420,15 @@ class TestSubmitPhotosForVerification(TestCase):
"Photo ID image is required if the user does not have an initial verification attempt." "Photo ID image is required if the user does not have an initial verification attempt."
) )
# Create the initial verification attempt # Create the initial verification attempt with some dummy
# value set for field 'photo_id_key'
self._submit_photos( self._submit_photos(
face_image=self.IMAGE_DATA, face_image=self.IMAGE_DATA,
photo_id_image=self.IMAGE_DATA, photo_id_image=self.IMAGE_DATA,
) )
attempt = SoftwareSecurePhotoVerification.objects.get(user=self.user)
attempt.photo_id_key = "dummy_photo_id_key"
attempt.save()
# Now the request should succeed # Now the request should succeed
self._submit_photos(face_image=self.IMAGE_DATA) self._submit_photos(face_image=self.IMAGE_DATA)
...@@ -2037,7 +2041,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase): ...@@ -2037,7 +2041,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
""" """
Helper method for initial verification. Helper method for initial verification.
""" """
attempt = SoftwareSecurePhotoVerification(user=self.user) attempt = SoftwareSecurePhotoVerification(user=self.user, photo_id_key="dummy_photo_id_key")
attempt.mark_ready() attempt.mark_ready()
attempt.save() attempt.save()
attempt.submit() attempt.submit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment