Ejemplo n.º 1
0
    def test_user_is_reverified_for_all(self):

        # if there are no windows for a course, this should return True
        self.assertTrue(
            SoftwareSecurePhotoVerification.user_is_reverified_for_all(
                self.course.id, self.user))

        # first, make three windows
        window1 = MidcourseReverificationWindowFactory(
            course_id=self.course.id,
            start_date=datetime.now(pytz.UTC) - timedelta(days=15),
            end_date=datetime.now(pytz.UTC) - timedelta(days=13),
        )

        window2 = MidcourseReverificationWindowFactory(
            course_id=self.course.id,
            start_date=datetime.now(pytz.UTC) - timedelta(days=10),
            end_date=datetime.now(pytz.UTC) - timedelta(days=8),
        )

        window3 = MidcourseReverificationWindowFactory(
            course_id=self.course.id,
            start_date=datetime.now(pytz.UTC) - timedelta(days=5),
            end_date=datetime.now(pytz.UTC) - timedelta(days=3),
        )

        # make two SSPMidcourseReverifications for those windows
        attempt1 = SoftwareSecurePhotoVerification(status="approved",
                                                   user=self.user,
                                                   window=window1)
        attempt1.save()

        attempt2 = SoftwareSecurePhotoVerification(status="approved",
                                                   user=self.user,
                                                   window=window2)
        attempt2.save()

        # should return False because only 2 of 3 windows have verifications
        self.assertFalse(
            SoftwareSecurePhotoVerification.user_is_reverified_for_all(
                self.course.id, self.user))

        attempt3 = SoftwareSecurePhotoVerification(status="must_retry",
                                                   user=self.user,
                                                   window=window3)
        attempt3.save()

        # should return False because the last verification exists BUT is not approved
        self.assertFalse(
            SoftwareSecurePhotoVerification.user_is_reverified_for_all(
                self.course.id, self.user))

        attempt3.status = "approved"
        attempt3.save()

        # should now return True because all windows have approved verifications
        self.assertTrue(
            SoftwareSecurePhotoVerification.user_is_reverified_for_all(
                self.course.id, self.user))
Ejemplo n.º 2
0
 def test_reverification(self):
     """
      Test software secure result for reverification window.
     """
     data = {
         "EdX-ID": self.receipt_id,
         "Result": "PASS",
         "Reason": "",
         "MessageType": "You have been verified."
     }
     window = MidcourseReverificationWindowFactory(course_id=self.course_id)
     self.attempt.window = window
     self.attempt.save()
     json_data = json.dumps(data)
     self.assertEqual(
         CourseEnrollment.objects.filter(course_id=self.course_id).count(),
         0)
     response = self.client.post(
         reverse('verify_student_results_callback'),
         data=json_data,
         content_type='application/json',
         HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing',
         HTTP_DATE='testdate')
     self.assertEquals(response.content, 'OK!')
     self.assertIsNotNone(
         CourseEnrollment.objects.get(course_id=self.course_id))
Ejemplo n.º 3
0
    def test_midcourse_reverify_post_success(self):
        window = MidcourseReverificationWindowFactory(
            course_id=self.course_key)
        url = reverse(
            'verify_student_midcourse_reverify',
            kwargs={'course_id': self.course_key.to_deprecated_string()})

        response = self.client.post(url, {'face_image': ','})

        # Check that submission event was logged
        self.mock_tracker.emit.assert_called_once_with(  # pylint: disable=maybe-no-member
            'edx.course.enrollment.reverify.submitted',
            {
                'user_id': self.user.id,
                'course_id': self.course_key.to_deprecated_string(),
                'mode': "verified",
            }
        )
        self.mock_tracker.emit.reset_mock()  # pylint: disable=maybe-no-member

        self.assertEquals(response.status_code, 302)
        try:
            verification_attempt = SoftwareSecurePhotoVerification.objects.get(
                user=self.user, window=window)
            self.assertIsNotNone(verification_attempt)
        except ObjectDoesNotExist:
            self.fail('No verification object generated')
Ejemplo n.º 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))
Ejemplo n.º 5
0
 def test_original_verification(self):
     orig_attempt = SoftwareSecurePhotoVerification(user=self.user)
     orig_attempt.save()
     window = MidcourseReverificationWindowFactory(
         course_id=self.course.id,
         start_date=datetime.now(pytz.UTC) - timedelta(days=15),
         end_date=datetime.now(pytz.UTC) - timedelta(days=13),
     )
     midcourse_attempt = SoftwareSecurePhotoVerification(user=self.user, window=window)
     self.assertEquals(midcourse_attempt.original_verification(user=self.user), orig_attempt)
Ejemplo n.º 6
0
    def test_user_status(self):
        # test for correct status when no error returned
        user = UserFactory.create()
        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('none', ''))

        # test for when one has been created
        attempt = SoftwareSecurePhotoVerification(user=user)
        attempt.status = 'approved'
        attempt.save()

        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('approved', ''))

        # create another one for the same user, make sure the right one is
        # returned
        attempt2 = SoftwareSecurePhotoVerification(user=user)
        attempt2.status = 'denied'
        attempt2.error_msg = '[{"photoIdReasons": ["Not provided"]}]'
        attempt2.save()

        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('approved', ''))

        # now delete the first one and verify that the denial is being handled
        # properly
        attempt.delete()
        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('must_reverify', "No photo ID was provided."))

        # test for correct status for reverifications
        window = MidcourseReverificationWindowFactory()
        reverify_status = SoftwareSecurePhotoVerification.user_status(user=user, window=window)
        self.assertEquals(reverify_status, ('must_reverify', ''))

        reverify_attempt = SoftwareSecurePhotoVerification(user=user, window=window)
        reverify_attempt.status = 'approved'
        reverify_attempt.save()

        reverify_status = SoftwareSecurePhotoVerification.user_status(user=user, window=window)
        self.assertEquals(reverify_status, ('approved', ''))

        reverify_attempt.status = 'denied'
        reverify_attempt.save()

        reverify_status = SoftwareSecurePhotoVerification.user_status(user=user, window=window)
        self.assertEquals(reverify_status, ('denied', ''))

        reverify_attempt.status = 'approved'
        # pylint: disable=protected-access
        reverify_attempt.created_at = SoftwareSecurePhotoVerification._earliest_allowed_date() + timedelta(days=-1)
        reverify_attempt.save()
        reverify_status = SoftwareSecurePhotoVerification.user_status(user=user, window=window)
        message = 'Your {platform_name} verification has expired.'.format(platform_name=settings.PLATFORM_NAME)
        self.assertEquals(reverify_status, ('expired', message))
Ejemplo n.º 7
0
 def setUp(self):
     self.user = UserFactory.create(username="******", password="******")
     self.client.login(username="******", password="******")
     self.course_id = 'Robot/999/Test_Course'
     CourseFactory.create(org='Robot', number='999', display_name=u'Test Course é')
     self.window = MidcourseReverificationWindowFactory(course_id=self.course_id)
     url = reverse('verify_student_midcourse_reverify', kwargs={'course_id': self.course_id})
     self.client.post(url, {'face_image': ','})
     photo_verification = SoftwareSecurePhotoVerification.objects.get(user=self.user, window=self.window)
     photo_verification.status = 'denied'
     photo_verification.save()
Ejemplo n.º 8
0
 def test_midcourse_reverify_post_failure_expired_window(self):
     window = MidcourseReverificationWindowFactory(
         course_id=self.course_key,
         start_date=datetime.now(pytz.UTC) - timedelta(days=100),
         end_date=datetime.now(pytz.UTC) - timedelta(days=50),
     )
     url = reverse('verify_student_midcourse_reverify', kwargs={'course_id': self.course_key.to_deprecated_string()})
     response = self.client.post(url, {'face_image': ','})
     self.assertEquals(response.status_code, 302)
     with self.assertRaises(ObjectDoesNotExist):
         SoftwareSecurePhotoVerification.objects.get(user=self.user, window=window)
Ejemplo n.º 9
0
    def test_midcourse_reverify_dash(self):
        url = reverse('verify_student_midcourse_reverify_dash')
        response = self.client.get(url)
        # not enrolled in any courses
        self.assertEquals(response.status_code, 200)

        enrollment = CourseEnrollment.get_or_create_enrollment(self.user, self.course_key)
        enrollment.update_enrollment(mode="verified", is_active=True)
        MidcourseReverificationWindowFactory(course_id=self.course_key)
        response = self.client.get(url)
        # enrolled in a verified course, and the window is open
        self.assertEquals(response.status_code, 200)
Ejemplo n.º 10
0
    def test_display(self):
        user = UserFactory.create()
        window = MidcourseReverificationWindowFactory()
        attempt = SoftwareSecurePhotoVerification(user=user, window=window, status="denied")
        attempt.save()

        # We expect the verification to be displayed by default
        self.assertEquals(SoftwareSecurePhotoVerification.display_status(user, window), True)

        # Turn it off
        SoftwareSecurePhotoVerification.display_off(user.id)
        self.assertEquals(SoftwareSecurePhotoVerification.display_status(user, window), False)
Ejemplo n.º 11
0
    def test_user_status(self):
        # test for correct status when no error returned
        user = UserFactory.create()
        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('none', ''))

        # test for when one has been created
        attempt = SoftwareSecurePhotoVerification(user=user)
        attempt.status = 'approved'
        attempt.save()

        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('approved', ''))

        # create another one for the same user, make sure the right one is
        # returned
        attempt2 = SoftwareSecurePhotoVerification(user=user)
        attempt2.status = 'denied'
        attempt2.error_msg = '[{"photoIdReasons": ["Not provided"]}]'
        attempt2.save()

        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status, ('approved', ''))

        # now delete the first one and verify that the denial is being handled
        # properly
        attempt.delete()
        status = SoftwareSecurePhotoVerification.user_status(user)
        self.assertEquals(status,
                          ('must_reverify', "No photo ID was provided."))

        # test for correct status for reverifications
        window = MidcourseReverificationWindowFactory()
        reverify_status = SoftwareSecurePhotoVerification.user_status(
            user=user, window=window)
        self.assertEquals(reverify_status, ('must_reverify', ''))

        reverify_attempt = SoftwareSecurePhotoVerification(user=user,
                                                           window=window)
        reverify_attempt.status = 'approved'
        reverify_attempt.save()

        reverify_status = SoftwareSecurePhotoVerification.user_status(
            user=user, window=window)
        self.assertEquals(reverify_status, ('approved', ''))

        reverify_attempt.status = 'denied'
        reverify_attempt.save()

        reverify_status = SoftwareSecurePhotoVerification.user_status(
            user=user, window=window)
        self.assertEquals(reverify_status, ('denied', ''))
Ejemplo n.º 12
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))
        )
    def test_with_two_verifications(self):
        # checking if a user has two verification and but most recent verification course deadline is expired

        self._setup_mode_and_enrollment(self.FUTURE, "verified")

        # The student has an approved verification
        attempt = SoftwareSecurePhotoVerification.objects.create(user=self.user)
        attempt.mark_ready()
        attempt.submit()
        attempt.approve()
        # Making created at to previous date to differentiate with 2nd attempt.
        attempt.created_at = datetime.now(UTC) - timedelta(days=1)
        attempt.save()

        # Expect that the successfully verified message is shown
        self._assert_course_verification_status(VERIFY_STATUS_APPROVED)

        # Check that the "verification good until" date is displayed
        response = self.client.get(self.dashboard_url)
        self.assertContains(response, attempt.expiration_datetime.strftime("%m/%d/%Y"))

        # Adding another verification with different course.
        # Its created_at is greater than course deadline.
        course2 = CourseFactory.create()
        CourseModeFactory(
            course_id=course2.id,
            mode_slug="verified",
            expiration_datetime=self.PAST
        )
        CourseEnrollmentFactory(
            course_id=course2.id,
            user=self.user,
            mode="verified"
        )

        window = MidcourseReverificationWindowFactory(course_id=course2.id)
        # The student has an approved verification
        attempt2 = SoftwareSecurePhotoVerification.objects.create(user=self.user)
        attempt2.mark_ready()
        attempt2.submit()
        attempt2.approve()
        attempt2.window = window
        attempt2.save()

        # Mark the attemp2 as approved so its date will appear on dasboard.
        self._assert_course_verification_status(VERIFY_STATUS_APPROVED)
        response2 = self.client.get(self.dashboard_url)
        self.assertContains(response2, attempt2.expiration_datetime.strftime("%m/%d/%Y"))
        self.assertEqual(response2.content.count(attempt2.expiration_datetime.strftime("%m/%d/%Y")), 2)
Ejemplo n.º 14
0
    def test_fetch_photo_id_image(self):
        user = UserFactory.create()
        orig_attempt = SoftwareSecurePhotoVerification(user=user, window=None)
        orig_attempt.save()

        old_key = orig_attempt.photo_id_key

        window = MidcourseReverificationWindowFactory(
            course_id=SlashSeparatedCourseKey("pony", "rainbow", "dash"),
            start_date=datetime.now(pytz.utc) - timedelta(days=5),
            end_date=datetime.now(pytz.utc) + timedelta(days=5))
        new_attempt = SoftwareSecurePhotoVerification(user=user, window=window)
        new_attempt.save()
        new_attempt.fetch_photo_id_image()
        assert_equals(new_attempt.photo_id_key, old_key)
Ejemplo n.º 15
0
    def test_user_has_valid_or_pending(self):
        window = MidcourseReverificationWindowFactory(
            course_id=self.course.id,
            start_date=datetime.now(pytz.UTC) - timedelta(days=15),
            end_date=datetime.now(pytz.UTC) - timedelta(days=13),
        )

        attempt = SoftwareSecurePhotoVerification(status="must_retry", user=self.user, window=window)
        attempt.save()

        assert_false(SoftwareSecurePhotoVerification.user_has_valid_or_pending(user=self.user, window=window))

        attempt.status = "approved"
        attempt.save()
        assert_true(SoftwareSecurePhotoVerification.user_has_valid_or_pending(user=self.user, window=window))