Example #1
0
    def skip_verification(self, user_id, course_id,
                          related_assessment_location):
        """Add skipped verification attempt entry for a user against a given
        'checkpoint'.

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

        Returns:
            None
        """
        course_key = CourseKey.from_string(course_id)
        checkpoint = VerificationCheckpoint.objects.get(
            course_id=course_key,
            checkpoint_location=related_assessment_location)

        # user can skip a reverification attempt only if that user has not already
        # skipped an attempt
        try:
            SkippedReverification.add_skipped_reverification_attempt(
                checkpoint, user_id, course_key)
        except IntegrityError:
            log.exception(
                "Skipped attempt already exists for user %s: with course %s:",
                user_id, unicode(course_id))
Example #2
0
    def test_add_skipped_attempts(self):
        """adding skipped re-verification object using class method."""

        # adding verification status
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )

        # getting the status from db
        result = SkippedReverification.objects.filter(course_id=self.course.id)[0]
        self.assertEqual(result.checkpoint, self.checkpoint)
        self.assertEqual(result.user, self.user)
        self.assertEqual(result.course_id, self.course.id)
Example #3
0
    def test_add_skipped_attempts(self):
        """adding skipped re-verification object using class method."""

        # adding verification status
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )

        # getting the status from db
        result = SkippedReverification.objects.filter(course_id=self.course.id)[0]
        self.assertEqual(result.checkpoint, self.checkpoint)
        self.assertEqual(result.user, self.user)
        self.assertEqual(result.course_id, self.course.id)
Example #4
0
    def test_add_skipped_attempts(self):
        """
        Test 'add_skipped_reverification_attempt' method.
        """

        # add verification status
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )

        # test the status of skipped reverification from database
        result = SkippedReverification.objects.filter(course_id=self.course.id)[0]
        self.assertEqual(result.checkpoint, self.checkpoint)
        self.assertEqual(result.user, self.user)
        self.assertEqual(result.course_id, self.course.id)
Example #5
0
    def get_status(self, user_id, course_id, related_assessment):
        """ Check if the user has any verification attempt or has skipped the verification

        Args:
            user_id(str): User Id string
            course_id(str): A string of course_id
            related_assessment(str): Verification checkpoint name

        Returns:
            "skipped" if has skip the re-verification or Verification Status string if
            any attempt submitted by user else None
        """
        course_key = CourseKey.from_string(course_id)
        has_skipped = SkippedReverification.check_user_skipped_reverification_exists(user_id, course_key)
        if has_skipped:
            return "skipped"
        try:
            checkpoint_status = VerificationStatus.objects.filter(
                user_id=user_id,
                checkpoint__course_id=course_key,
                checkpoint__checkpoint_name=related_assessment
            ).latest()
            return checkpoint_status.status
        except ObjectDoesNotExist:
            return None
Example #6
0
    def get_status(self, user_id, course_id, related_assessment_location):
        """Get verification attempt status 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: str or None
        """
        user = User.objects.get(id=user_id)
        course_key = CourseKey.from_string(course_id)

        if not CourseEnrollment.is_enrolled_as_verified(user, course_key):
            return self.NON_VERIFIED_TRACK
        elif SkippedReverification.check_user_skipped_reverification_exists(user_id, course_key):
            return self.SKIPPED_STATUS

        try:
            checkpoint_status = VerificationStatus.objects.filter(
                user_id=user_id,
                checkpoint__course_id=course_key,
                checkpoint__checkpoint_location=related_assessment_location
            ).latest()
            return checkpoint_status.status
        except ObjectDoesNotExist:
            return None
Example #7
0
    def test_check_user_skipped_reverification_exists(self):
        """Checking check_user_skipped_reverification_exists method returns boolean status"""

        # adding verification status
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )

        self.assertTrue(
            SkippedReverification.check_user_skipped_reverification_exists(course_id=self.course.id, user=self.user)
        )

        user2 = UserFactory.create()
        self.assertFalse(
            SkippedReverification.check_user_skipped_reverification_exists(course_id=self.course.id, user=user2)
        )
Example #8
0
    def test_check_user_skipped_reverification_exists(self):
        """
        Test the 'check_user_skipped_reverification_exists' method's response.
        """
        # add verification status
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )
        self.assertTrue(
            SkippedReverification.check_user_skipped_reverification_exists(course_id=self.course.id, user=self.user)
        )

        user2 = UserFactory.create()
        self.assertFalse(
            SkippedReverification.check_user_skipped_reverification_exists(course_id=self.course.id, user=user2)
        )
Example #9
0
    def get_status(self, user_id, course_id, related_assessment_location):
        """Get verification attempt status 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:
            "skipped" if the user has skipped the re-verification or
            Verification Status string if the user has submitted photo
            verification attempt else None
        """
        course_key = CourseKey.from_string(course_id)
        has_skipped = SkippedReverification.check_user_skipped_reverification_exists(user_id, course_key)
        if has_skipped:
            return "skipped"
        try:
            checkpoint_status = VerificationStatus.objects.filter(
                user_id=user_id,
                checkpoint__course_id=course_key,
                checkpoint__checkpoint_location=related_assessment_location
            ).latest()
            return checkpoint_status.status
        except ObjectDoesNotExist:
            return None
Example #10
0
    def test_check_user_skipped_reverification_exists(self):
        """Checking check_user_skipped_reverification_exists method returns boolean status"""

        # adding verification status
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )

        self.assertTrue(
            SkippedReverification.check_user_skipped_reverification_exists(course_id=self.course.id, user=self.user)
        )

        user2 = UserFactory.create()
        self.assertFalse(
            SkippedReverification.check_user_skipped_reverification_exists(course_id=self.course.id, user=user2)
        )
Example #11
0
    def skip_verification(self, checkpoint_name, user_id, course_id):
        """Create the add verification attempt

        Args:
            course_id(str): A string of course_id
            user_id(str): User Id string
            checkpoint_name(str): Verification checkpoint name

        Returns:
            None
        """
        course_key = CourseKey.from_string(course_id)
        checkpoint = VerificationCheckpoint.objects.get(course_id=course_key, checkpoint_name=checkpoint_name)

        # if user do not already skipped the attempt for this course only then he can skip
        try:
            SkippedReverification.add_skipped_reverification_attempt(checkpoint, user_id, course_key)
        except IntegrityError:
            log.exception("Skipped attempt already exists for user %s: with course %s:", user_id, unicode(course_id))
Example #12
0
    def skip_verification(self, user_id, course_id, related_assessment_location):
        """Add skipped verification attempt entry for a user against a given
        'checkpoint'.

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

        Returns:
            None
        """
        course_key = CourseKey.from_string(course_id)
        checkpoint = VerificationCheckpoint.objects.get(
            course_id=course_key,
            checkpoint_location=related_assessment_location
        )
        user = User.objects.get(id=user_id)

        # user can skip a reverification attempt only if that user has not already
        # skipped an attempt
        try:
            SkippedReverification.add_skipped_reverification_attempt(checkpoint, user_id, course_key)
        except IntegrityError:
            log.exception("Skipped attempt already exists for user %s: with course %s:", user_id, unicode(course_id))
            return

        try:
            # Avoid circular import
            from openedx.core.djangoapps.credit.api import set_credit_requirement_status

            # As a user skips the reverification it declines to fulfill the requirement so
            # requirement sets to declined.
            set_credit_requirement_status(
                user.username,
                course_key,
                'reverification',
                checkpoint.checkpoint_location,
                status='declined'
            )

        except Exception as err:  # pylint: disable=broad-except
            log.error("Unable to add credit requirement status for user with id %d: %s", user_id, err)
Example #13
0
    def test_unique_constraint(self):
        """adding skipped re-verification with same user and course id will
        raise integrity exception
        """

        # adding verification object
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
        )

        with self.assertRaises(IntegrityError):
            SkippedReverification.add_skipped_reverification_attempt(
                checkpoint=self.checkpoint, user_id=self.user.id, course_id=unicode(self.course.id)
            )

        # Create skipped attempt for different user
        user2 = UserFactory.create()
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint, user_id=user2.id, course_id=unicode(self.course.id)
        )

        # getting the status from db
        result = SkippedReverification.objects.filter(user=user2)[0]
        self.assertEqual(result.checkpoint, self.checkpoint)
        self.assertEqual(result.user, user2)
        self.assertEqual(result.course_id, self.course.id)
Example #14
0
    def test_unique_constraint(self):
        """Test that adding skipped re-verification with same user and course
        id will raise 'IntegrityError' exception.
        """
        # add verification object
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint,
            user_id=self.user.id,
            course_id=unicode(self.course.id))
        with self.assertRaises(IntegrityError):
            SkippedReverification.add_skipped_reverification_attempt(
                checkpoint=self.checkpoint,
                user_id=self.user.id,
                course_id=unicode(self.course.id))

        # create skipped attempt for different user
        user2 = UserFactory.create()
        SkippedReverification.add_skipped_reverification_attempt(
            checkpoint=self.checkpoint,
            user_id=user2.id,
            course_id=unicode(self.course.id))

        # test the status of skipped reverification from database
        result = SkippedReverification.objects.filter(user=user2)[0]
        self.assertEqual(result.checkpoint, self.checkpoint)
        self.assertEqual(result.user, user2)
        self.assertEqual(result.course_id, self.course.id)
Example #15
0
    def skip_verification(self, user_id, course_id, related_assessment_location):
        """Add skipped verification attempt entry for a user against a given
        'checkpoint'.

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

        Returns:
            None
        """
        course_key = CourseKey.from_string(course_id)
        checkpoint = VerificationCheckpoint.objects.get(
            course_id=course_key,
            checkpoint_location=related_assessment_location
        )

        # user can skip a reverification attempt only if that user has not already
        # skipped an attempt
        try:
            SkippedReverification.add_skipped_reverification_attempt(checkpoint, user_id, course_key)
        except IntegrityError:
            log.exception("Skipped attempt already exists for user %s: with course %s:", user_id, unicode(course_id))