Commit 7427d82c by Edward Zarecor

Merge pull request #10058 from edx/hotfix/2015-10-06b

Hotfix/2015 10 06b
parents 882c2fa3 7e55437d
......@@ -11,13 +11,31 @@ class Command(BaseCommand):
This method finds those PhotoVerifications with a status of
MUST_RETRY and attempts to verify them.
"""
help = 'Retries SoftwareSecurePhotoVerifications that are in a state of \'must_retry\''
args = "<SoftwareSecurePhotoVerification id, SoftwareSecurePhotoVerification id, ...>"
help = (
"Retries SoftwareSecurePhotoVerifications passed as "
"arguments, or if no arguments are supplied, all that "
"are in a state of 'must_retry'"
)
def handle(self, *args, **options):
attempts_to_retry = SoftwareSecurePhotoVerification.objects.filter(status='must_retry')
if args:
attempts_to_retry = SoftwareSecurePhotoVerification.objects.filter(
receipt_id__in=args
)
force_must_retry = True
else:
attempts_to_retry = SoftwareSecurePhotoVerification.objects.filter(status='must_retry')
force_must_retry = False
print("Attempting to retry {0} failed PhotoVerification submissions".format(len(attempts_to_retry)))
for index, attempt in enumerate(attempts_to_retry):
print("Retrying submission #{0} (ID: {1}, User: {2})".format(index, attempt.id, attempt.user))
attempt.submit()
# Set the attempts status to 'must_retry' so that we can re-submit it
if force_must_retry:
attempt.status = 'must_retry'
attempt.submit(copy_id_photo_from=attempt.copy_id_photo_from)
print("Retry result: {0}".format(attempt.status))
print("Done resubmitting failed photo verifications")
"""
Manually set Software Secure verification status.
"""
import sys
from django.core.management.base import BaseCommand
from verify_student.models import (
SoftwareSecurePhotoVerification, VerificationCheckpoint, VerificationStatus
)
class Command(BaseCommand):
"""
Command to trigger the actions that would normally follow Software Secure
returning with the results of a photo verification.
"""
args = "<{approved, denied}, SoftwareSecurePhotoVerification id, [reason_for_denial]>"
def handle(self, *args, **kwargs): # pylint: disable=unused-argument
from verify_student.views import _set_user_requirement_status
status_to_set = args[0]
receipt_id = args[1]
try:
attempt = SoftwareSecurePhotoVerification.objects.get(receipt_id=receipt_id)
except SoftwareSecurePhotoVerification.DoesNotExist:
self.stderr.write(
'SoftwareSecurePhotoVerification with id {id} could not be found.\n'.format(id=receipt_id)
)
sys.exit(1)
if status_to_set == 'approved':
self.stdout.write('Approving verification for {id}.\n'.format(id=receipt_id))
attempt.approve()
_set_user_requirement_status(attempt, 'reverification', 'satisfied')
elif status_to_set == 'denied':
self.stdout.write('Denying verification for {id}.\n'.format(id=receipt_id))
if len(args) >= 3:
reason_for_denial = args[2]
else:
reason_for_denial = 'Denied via management command.'
attempt.deny(reason_for_denial)
_set_user_requirement_status(attempt, 'reverification', 'failed', reason_for_denial)
else:
self.stdout.write('Cannot set id {id} to unrecognized status {status}'.format(
id=receipt_id, status=status_to_set
))
sys.exit(1)
checkpoints = VerificationCheckpoint.objects.filter(photo_verification=attempt).all()
VerificationStatus.add_status_from_checkpoints(
checkpoints=checkpoints,
user=attempt.user,
status=status_to_set
)
......@@ -588,16 +588,23 @@ class SoftwareSecurePhotoVerification(PhotoVerification):
photo_id_key = models.TextField(max_length=1024)
IMAGE_LINK_DURATION = 5 * 60 * 60 * 24 # 5 days in seconds
copy_id_photo_from = models.ForeignKey("self", null=True, blank=True)
@classmethod
def get_initial_verification(cls, user):
"""Get initial verification for a user
"""Get initial verification for a user with the 'photo_id_key'.
Arguments:
user(User): user object
Return:
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
@status_before_must_be("created")
......
......@@ -472,6 +472,38 @@ class TestPhotoVerification(ModuleStoreTestCase):
status = SoftwareSecurePhotoVerification.verification_status_for_user(user, course.id, enrollment_mode)
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
class VerificationCheckpointTest(ModuleStoreTestCase):
......
......@@ -1420,11 +1420,15 @@ class TestSubmitPhotosForVerification(TestCase):
"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(
face_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
self._submit_photos(face_image=self.IMAGE_DATA)
......@@ -2037,7 +2041,7 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
"""
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.save()
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