예제 #1
0
    def test_get_window(self):
        # if no window exists, returns None
        self.assertIsNone(MidcourseReverificationWindow.get_window(self.course_id, datetime.now(pytz.utc)))

        # we should get the expected window otherwise
        window_valid = MidcourseReverificationWindowFactory(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=3),
            end_date=datetime.now(pytz.utc) + timedelta(days=3)
        )
        self.assertEquals(
            window_valid,
            MidcourseReverificationWindow.get_window(self.course_id, datetime.now(pytz.utc))
        )
예제 #2
0
    def test_get_window(self):
        # if no window exists, returns None
        self.assertIsNone(MidcourseReverificationWindow.get_window(self.course_id, datetime.now(pytz.utc)))

        # we should get the expected window otherwise
        window_valid = MidcourseReverificationWindowFactory(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=3),
            end_date=datetime.now(pytz.utc) + timedelta(days=3)
        )
        self.assertEquals(
            window_valid,
            MidcourseReverificationWindow.get_window(self.course_id, datetime.now(pytz.utc))
        )
예제 #3
0
    def post(self, request, course_id):
        """
        submits the reverification to SoftwareSecure
        """
        try:
            now = datetime.datetime.now(UTC)
            course_id = CourseKey.from_string(course_id)
            window = MidcourseReverificationWindow.get_window(course_id, now)
            if window is None:
                raise WindowExpiredException
            attempt = SoftwareSecurePhotoVerification(user=request.user, window=window)
            b64_face_image = request.POST["face_image"].split(",")[1]

            attempt.upload_face_image(b64_face_image.decode("base64"))
            attempt.fetch_photo_id_image()
            attempt.mark_ready()

            attempt.save()
            attempt.submit()
            course_enrollment = CourseEnrollment.get_or_create_enrollment(request.user, course_id)
            course_enrollment.update_enrollment(mode="verified")
            course_enrollment.emit_event(EVENT_NAME_USER_SUBMITTED_MIDCOURSE_REVERIFY)
            return HttpResponseRedirect(reverse("verify_student_midcourse_reverification_confirmation"))

        except WindowExpiredException:
            log.exception(
                "User {} attempted to re-verify, but the window expired before the attempt".format(request.user.id)
            )
            return HttpResponseRedirect(reverse("verify_student_reverification_window_expired"))

        except Exception:
            log.exception("Could not submit verification attempt for user {}".format(request.user.id))
            context = {"user_full_name": request.user.profile.name, "error": True}
            return render_to_response("verify_student/midcourse_photo_reverification.html", context)
예제 #4
0
    def test_window_open_for_course(self):
        # Should return False if no windows exist for a course
        self.assertFalse(MidcourseReverificationWindow.window_open_for_course(self.course_id))

        # Should return False if a window exists, but it's not in the current timeframe
        MidcourseReverificationWindowFactory(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=10),
            end_date=datetime.now(pytz.utc) - timedelta(days=5)
        )
        self.assertFalse(MidcourseReverificationWindow.window_open_for_course(self.course_id))

        # Should return True if a non-expired window exists
        MidcourseReverificationWindowFactory(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=3),
            end_date=datetime.now(pytz.utc) + timedelta(days=3)
        )
        self.assertTrue(MidcourseReverificationWindow.window_open_for_course(self.course_id))
예제 #5
0
    def test_window_open_for_course(self):
        # Should return False if no windows exist for a course
        self.assertFalse(MidcourseReverificationWindow.window_open_for_course(self.course_id))

        # Should return False if a window exists, but it's not in the current timeframe
        MidcourseReverificationWindowFactory(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=10),
            end_date=datetime.now(pytz.utc) - timedelta(days=5)
        )
        self.assertFalse(MidcourseReverificationWindow.window_open_for_course(self.course_id))

        # Should return True if a non-expired window exists
        MidcourseReverificationWindowFactory(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=3),
            end_date=datetime.now(pytz.utc) + timedelta(days=3)
        )
        self.assertTrue(MidcourseReverificationWindow.window_open_for_course(self.course_id))
예제 #6
0
    def test_no_overlapping_windows(self):
        window_valid = MidcourseReverificationWindow(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=3),
            end_date=datetime.now(pytz.utc) + timedelta(days=3))
        window_valid.save()

        with self.assertRaises(ValidationError):
            window_invalid = MidcourseReverificationWindow(
                course_id=self.course_id,
                start_date=datetime.now(pytz.utc) - timedelta(days=2),
                end_date=datetime.now(pytz.utc) + timedelta(days=4))
            window_invalid.save()
예제 #7
0
    def post(self, request, course_id):
        """
        submits the reverification to SoftwareSecure
        """
        try:
            now = datetime.datetime.now(UTC)
            course_id = SlashSeparatedCourseKey.from_deprecated_string(
                course_id)
            window = MidcourseReverificationWindow.get_window(course_id, now)
            if window is None:
                raise WindowExpiredException
            attempt = SoftwareSecurePhotoVerification(user=request.user,
                                                      window=window)
            b64_face_image = request.POST['face_image'].split(",")[1]

            attempt.upload_face_image(b64_face_image.decode('base64'))
            attempt.fetch_photo_id_image()
            attempt.mark_ready()

            attempt.save()
            attempt.submit()
            course_enrollment = CourseEnrollment.get_or_create_enrollment(
                request.user, course_id)
            course_enrollment.update_enrollment(mode="verified")
            course_enrollment.emit_event(
                EVENT_NAME_USER_SUBMITTED_MIDCOURSE_REVERIFY)
            return HttpResponseRedirect(
                reverse(
                    'verify_student_midcourse_reverification_confirmation'))

        except WindowExpiredException:
            log.exception(
                "User {} attempted to re-verify, but the window expired before the attempt"
                .format(request.user.id))
            return HttpResponseRedirect(
                reverse('verify_student_reverification_window_expired'))

        except Exception:
            log.exception(
                "Could not submit verification attempt for user {}".format(
                    request.user.id))
            context = {
                "user_full_name": request.user.profile.name,
                "error": True,
            }
            return render_to_response(
                "verify_student/midcourse_photo_reverification.html", context)
예제 #8
0
    def test_no_overlapping_windows(self):
        window_valid = MidcourseReverificationWindow(
            course_id=self.course_id,
            start_date=datetime.now(pytz.utc) - timedelta(days=3),
            end_date=datetime.now(pytz.utc) + timedelta(days=3)
        )
        window_valid.save()

        with self.assertRaises(ValidationError):
            window_invalid = MidcourseReverificationWindow(
                course_id=self.course_id,
                start_date=datetime.now(pytz.utc) - timedelta(days=2),
                end_date=datetime.now(pytz.utc) + timedelta(days=4)
            )
            window_invalid.save()