Пример #1
0
    def add_verification_status(self, user, status):
        """Adding the verification status for a user."""

        VerificationStatus.add_status_from_checkpoints(
            checkpoints=[self.first_checkpoint],
            user=user,
            status=status
        )
Пример #2
0
    def test_get_user_attempts(self):
        """
        Test adding verification status.
        """
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status='submitted')

        actual_attempts = VerificationStatus.get_user_attempts(
            self.user.id, self.course.id, self.first_checkpoint_location)
        self.assertEqual(actual_attempts, 1)
Пример #3
0
    def test_add_verification_status(self, status):
        """ Adding verification status using the class method. """

        # adding verification status
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint, user=self.user, status=status)

        # test the status from database
        result = VerificationStatus.objects.filter(
            checkpoint=self.first_checkpoint)[0]
        self.assertEqual(result.status, status)
        self.assertEqual(result.user, self.user)
def _get_user_statuses(user, course_key, checkpoint):
    """
    Retrieve all the information we need to determine the user's group.

    This will retrieve the information as a multi-get from the cache.

    Args:
        user (User): User object
        course_key (CourseKey): Identifier for the course.
        checkpoint (unicode): Location of the checkpoint in the course (serialized usage key)

    Returns:
        tuple of booleans of the form (is_verified, has_skipped, has_completed)

    """
    enrollment_cache_key = CourseEnrollment.cache_key_name(user.id, unicode(course_key))
    has_skipped_cache_key = SkippedReverification.cache_key_name(user.id, unicode(course_key))
    verification_status_cache_key = VerificationStatus.cache_key_name(user.id, unicode(course_key))

    # Try a multi-get from the cache
    cache_values = cache.get_many([
        enrollment_cache_key,
        has_skipped_cache_key,
        verification_status_cache_key
    ])

    # Retrieve whether the user is enrolled in a verified mode.
    is_verified = cache_values.get(enrollment_cache_key)
    if is_verified is None:
        is_verified = CourseEnrollment.is_enrolled_as_verified(user, course_key)
        cache.set(enrollment_cache_key, is_verified)

    # Retrieve whether the user has skipped any checkpoints in this course
    has_skipped = cache_values.get(has_skipped_cache_key)
    if has_skipped is None:
        has_skipped = SkippedReverification.check_user_skipped_reverification_exists(user, course_key)
        cache.set(has_skipped_cache_key, has_skipped)

    # Retrieve the user's verification status for each checkpoint in the course.
    verification_statuses = cache_values.get(verification_status_cache_key)
    if verification_statuses is None:
        verification_statuses = VerificationStatus.get_all_checkpoints(user.id, course_key)
        cache.set(verification_status_cache_key, verification_statuses)

    # Check whether the user has completed this checkpoint
    # "Completion" here means *any* submission, regardless of its status
    # since we want to show the user the content if they've submitted
    # photos.
    checkpoint = verification_statuses.get(checkpoint)
    has_completed_check = bool(checkpoint)

    return (is_verified, has_skipped, has_completed_check)
Пример #5
0
    def test_add_verification_status(self, status):
        """ Adding verification status using the class method. """

        # adding verification status
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status=status
        )

        # test the status from database
        result = VerificationStatus.objects.filter(checkpoint=self.first_checkpoint)[0]
        self.assertEqual(result.status, status)
        self.assertEqual(result.user, self.user)
Пример #6
0
    def test_get_user_attempts(self):
        """
        Test adding verification status.
        """
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status='submitted'
        )

        actual_attempts = VerificationStatus.get_user_attempts(
            self.user.id,
            self.course.id,
            self.first_checkpoint_location
        )
        self.assertEqual(actual_attempts, 1)
Пример #7
0
    def test_get_location_id(self):
        """
        Getting location id for a specific checkpoint.
        """

        # creating software secure attempt against checkpoint
        self.first_checkpoint.add_verification_attempt(SoftwareSecurePhotoVerification.objects.create(user=self.user))

        # add initial verification status for checkpoint
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status='submitted',
        )
        attempt = SoftwareSecurePhotoVerification.objects.filter(user=self.user)

        self.assertIsNotNone(VerificationStatus.get_location_id(attempt))
        self.assertEqual(VerificationStatus.get_location_id(None), '')
    def handle(self, *args, **kwargs):  # pylint: disable=unused-argument
        from lms.djangoapps.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)
Пример #9
0
    def test_get_location_id(self):
        """
        Getting location id for a specific checkpoint.
        """

        # creating software secure attempt against checkpoint
        self.first_checkpoint.add_verification_attempt(
            SoftwareSecurePhotoVerification.objects.create(user=self.user))

        # add initial verification status for checkpoint
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status='submitted',
        )
        attempt = SoftwareSecurePhotoVerification.objects.filter(
            user=self.user)

        self.assertIsNotNone(VerificationStatus.get_location_id(attempt))
        self.assertEqual(VerificationStatus.get_location_id(None), '')
    def handle(self, *args, **kwargs):  # pylint: disable=unused-argument
        from lms.djangoapps.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
        )
Пример #11
0
    def get_attempts(self, user_id, course_id, related_assessment_location):
        """Get re-verification attempts against a user for a given 'checkpoint'
        and 'course_id'.

        Args:
            user_id(str): User Id string
            course_id(str): A string of course id
            related_assessment_location(str): Location of Reverification XBlock

        Returns:
            Number of re-verification attempts of a user
        """
        course_key = CourseKey.from_string(course_id)
        return VerificationStatus.get_user_attempts(user_id, course_key, related_assessment_location)
Пример #12
0
    def get_attempts(self, user_id, course_id, related_assessment_location):
        """Get re-verification attempts against a user for a given 'checkpoint'
        and 'course_id'.

        Args:
            user_id(str): User Id string
            course_id(str): A string of course id
            related_assessment_location(str): Location of Reverification XBlock

        Returns:
            Number of re-verification attempts of a user
        """
        course_key = CourseKey.from_string(course_id)
        return VerificationStatus.get_user_attempts(user_id, course_key, related_assessment_location)
Пример #13
0
    def test_add_status_from_checkpoints(self, status):
        """Test verification status for reverification checkpoints after
        submitting software secure photo verification.
        """

        # add initial verification status for checkpoints
        initial_status = "submitted"
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status=initial_status)
        VerificationStatus.add_verification_status(
            checkpoint=self.second_checkpoint,
            user=self.user,
            status=initial_status)

        # now add verification status for multiple checkpoint points
        VerificationStatus.add_status_from_checkpoints(
            checkpoints=[self.first_checkpoint, self.second_checkpoint],
            user=self.user,
            status=status)

        # test that verification status entries with new status have been added
        # for both checkpoints
        result = VerificationStatus.objects.filter(
            user=self.user, checkpoint=self.first_checkpoint)
        self.assertEqual(len(result),
                         len(self.first_checkpoint.checkpoint_status.all()))
        self.assertEqual(
            list(
                result.values_list('checkpoint__checkpoint_location',
                                   flat=True)),
            list(
                self.first_checkpoint.checkpoint_status.values_list(
                    'checkpoint__checkpoint_location', flat=True)))

        result = VerificationStatus.objects.filter(
            user=self.user, checkpoint=self.second_checkpoint)
        self.assertEqual(len(result),
                         len(self.second_checkpoint.checkpoint_status.all()))
        self.assertEqual(
            list(
                result.values_list('checkpoint__checkpoint_location',
                                   flat=True)),
            list(
                self.second_checkpoint.checkpoint_status.values_list(
                    'checkpoint__checkpoint_location', flat=True)))
Пример #14
0
    def test_add_status_from_checkpoints(self, status):
        """Test verification status for reverification checkpoints after
        submitting software secure photo verification.
        """

        # add initial verification status for checkpoints
        initial_status = "submitted"
        VerificationStatus.add_verification_status(
            checkpoint=self.first_checkpoint,
            user=self.user,
            status=initial_status
        )
        VerificationStatus.add_verification_status(
            checkpoint=self.second_checkpoint,
            user=self.user,
            status=initial_status
        )

        # now add verification status for multiple checkpoint points
        VerificationStatus.add_status_from_checkpoints(
            checkpoints=[self.first_checkpoint, self.second_checkpoint], user=self.user, status=status
        )

        # test that verification status entries with new status have been added
        # for both checkpoints
        result = VerificationStatus.objects.filter(user=self.user, checkpoint=self.first_checkpoint)
        self.assertEqual(len(result), len(self.first_checkpoint.checkpoint_status.all()))
        self.assertEqual(
            list(result.values_list('checkpoint__checkpoint_location', flat=True)),
            list(self.first_checkpoint.checkpoint_status.values_list('checkpoint__checkpoint_location', flat=True))
        )

        result = VerificationStatus.objects.filter(user=self.user, checkpoint=self.second_checkpoint)
        self.assertEqual(len(result), len(self.second_checkpoint.checkpoint_status.all()))
        self.assertEqual(
            list(result.values_list('checkpoint__checkpoint_location', flat=True)),
            list(self.second_checkpoint.checkpoint_status.values_list('checkpoint__checkpoint_location', flat=True))
        )