def test_get_studentview_unstarted_timed_exam_with_allowance(self):
        """
        Test for get_student_view Timed exam which is not proctored and has not started yet.
        But user has an allowance
        """

        allowed_extra_time = 10
        add_allowance_for_user(
            self.timed_exam_id, self.user.username,
            ProctoredExamStudentAllowance.ADDITIONAL_TIME_GRANTED,
            six.text_type(allowed_extra_time))

        rendered_response = get_student_view(user_id=self.user_id,
                                             course_id=self.course_id,
                                             content_id=self.content_id_timed,
                                             context={})
        self.assertNotIn(
            'data-exam-id="{proctored_exam_id}"'.format(
                proctored_exam_id=self.proctored_exam_id), rendered_response)
        self.assertIn(self.timed_exam_msg.format(exam_name=self.exam_name),
                      rendered_response)
        self.assertIn('31 minutes', rendered_response)
        self.assertNotIn(
            self.start_an_exam_msg.format(exam_name=self.exam_name),
            rendered_response)
    def test_get_studentview_unstarted_timed_exam_with_allowance(self):
        """
        Test for get_student_view Timed exam which is not proctored and has not started yet.
        But user has an allowance
        """

        allowed_extra_time = 10
        add_allowance_for_user(
            self.timed_exam_id,
            self.user.username,
            ProctoredExamStudentAllowance.ADDITIONAL_TIME_GRANTED,
            six.text_type(allowed_extra_time)
        )

        rendered_response = get_student_view(
            user_id=self.user_id,
            course_id=self.course_id,
            content_id=self.content_id_timed,
            context={}
        )
        self.assertNotIn(
            'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id),
            rendered_response
        )
        self.assertIn(self.timed_exam_msg.format(exam_name=self.exam_name), rendered_response)
        self.assertIn('31 minutes', rendered_response)
        self.assertNotIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response)
Beispiel #3
0
    def test_attempt_with_review_policy(self, review_policy_exception):
        """
        Create an unstarted proctoring attempt with a review policy associated with it.
        """

        exam_id = create_exam(course_id='foo/bar/baz',
                              content_id='content',
                              exam_name='Sample Exam',
                              time_limit_mins=10,
                              is_proctored=True)

        if review_policy_exception:
            add_allowance_for_user(
                exam_id, self.user.id,
                ProctoredExamStudentAllowance.REVIEW_POLICY_EXCEPTION,
                review_policy_exception)

        policy = ProctoredExamReviewPolicy.objects.create(
            set_by_user_id=self.user.id,
            proctored_exam_id=exam_id,
            review_policy='Foo Policy')

        def assert_get_payload_mock(exam, context):
            """
            Add a mock shim so we can assert that the _get_payload has been called with the right
            review policy
            """
            self.assertIn('review_policy', context)
            self.assertEqual(policy.review_policy, context['review_policy'])

            # call into real implementation
            result = get_backend_provider(emphemeral=True)._get_payload(
                exam, context)

            # assert that this is in the 'reviewerNotes' field that is passed to SoftwareSecure
            expected = context['review_policy']
            if review_policy_exception:
                expected = '{base}; {exception}'.format(
                    base=expected, exception=review_policy_exception)

            self.assertEqual(result['reviewerNotes'], expected)
            return result

        with HTTMock(mock_response_content):
            # patch the _get_payload method on the backend provider
            # so that we can assert that we are called with the review policy
            # as well as asserting that _get_payload includes that review policy
            # that was passed in
            with patch.object(get_backend_provider(), '_get_payload',
                              assert_get_payload_mock):
                attempt_id = create_exam_attempt(exam_id,
                                                 self.user.id,
                                                 taking_as_proctored=True)
                self.assertGreater(attempt_id, 0)

                # make sure we recorded the policy id at the time this was created
                attempt = get_exam_attempt_by_id(attempt_id)
                self.assertEqual(attempt['review_policy_id'], policy.id)
    def test_attempt_with_review_policy(self, review_policy_exception):
        """
        Create an unstarted proctoring attempt with a review policy associated with it.
        """

        exam_id = create_exam(
            course_id="foo/bar/baz",
            content_id="content",
            exam_name="Sample Exam",
            time_limit_mins=10,
            is_proctored=True,
        )

        if review_policy_exception:
            add_allowance_for_user(
                exam_id, self.user.id, ProctoredExamStudentAllowance.REVIEW_POLICY_EXCEPTION, review_policy_exception
            )

        policy = ProctoredExamReviewPolicy.objects.create(
            set_by_user_id=self.user.id, proctored_exam_id=exam_id, review_policy="Foo Policy"
        )

        def assert_get_payload_mock(exam, context):
            """
            Add a mock shim so we can assert that the _get_payload has been called with the right
            review policy
            """
            self.assertIn("review_policy", context)
            self.assertEqual(policy.review_policy, context["review_policy"])

            # call into real implementation
            result = get_backend_provider(emphemeral=True)._get_payload(exam, context)

            # assert that this is in the 'reviewerNotes' field that is passed to SoftwareSecure
            expected = context["review_policy"]
            if review_policy_exception:
                expected = "{base}; {exception}".format(base=expected, exception=review_policy_exception)

            self.assertEqual(result["reviewerNotes"], expected)
            return result

        with HTTMock(mock_response_content):
            # patch the _get_payload method on the backend provider
            # so that we can assert that we are called with the review policy
            # as well as asserting that _get_payload includes that review policy
            # that was passed in
            with patch.object(get_backend_provider(), "_get_payload", assert_get_payload_mock):
                attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
                self.assertGreater(attempt_id, 0)

                # make sure we recorded the policy id at the time this was created
                attempt = get_exam_attempt_by_id(attempt_id)
                self.assertEqual(attempt["review_policy_id"], policy.id)
Beispiel #5
0
 def put(self, request):
     """
     HTTP GET handler. Adds or updates Allowance
     """
     return Response(add_allowance_for_user(
         exam_id=request.data.get('exam_id', None),
         user_info=request.data.get('user_info', None),
         key=request.data.get('key', None),
         value=request.data.get('value', None)
     ))
Beispiel #6
0
 def put(self, request):
     """
     HTTP GET handler. Adds or updates Allowance
     """
     return Response(add_allowance_for_user(
         exam_id=request.data.get('exam_id', None),
         user_info=request.data.get('user_info', None),
         key=request.data.get('key', None),
         value=request.data.get('value', None)
     ))
Beispiel #7
0
    def put(self, request):
        """
        HTTP GET handler. Adds or updates Allowance
        """
        try:
            return Response(
                add_allowance_for_user(
                    exam_id=request.DATA.get('exam_id', None),
                    user_info=request.DATA.get('user_info', None),
                    key=request.DATA.get('key', None),
                    value=request.DATA.get('value', None)))

        except UserNotFoundException, ex:
            LOG.exception(ex)
            return Response(status=status.HTTP_400_BAD_REQUEST,
                            data={"detail": str(ex)})
Beispiel #8
0
    def put(self, request):
        """
        HTTP GET handler. Adds or updates Allowance
        """
        try:
            return Response(
                add_allowance_for_user(
                    exam_id=request.data.get("exam_id", None),
                    user_info=request.data.get("user_info", None),
                    key=request.data.get("key", None),
                    value=request.data.get("value", None),
                )
            )

        except (AllowanceValueNotAllowedException, UserNotFoundException, ProctoredExamNotActiveException) as ex:
            LOG.exception(ex)
            return Response(status=status.HTTP_400_BAD_REQUEST, data={"detail": str(ex)})
Beispiel #9
0
    def put(self, request):
        """
        HTTP GET handler. Adds or updates Allowance
        """
        try:
            return Response(add_allowance_for_user(
                exam_id=request.DATA.get('exam_id', None),
                user_info=request.DATA.get('user_info', None),
                key=request.DATA.get('key', None),
                value=request.DATA.get('value', None)
            ))

        except UserNotFoundException, ex:
            LOG.exception(ex)
            return Response(
                status=status.HTTP_400_BAD_REQUEST,
                data={"detail": str(ex)}
            )
    def test_attempt_with_review_policy(self, review_policy_exception):
        """
        Create an unstarted proctoring attempt with a review policy associated with it.
        """

        exam_id = create_exam(
            course_id='foo/bar/baz',
            content_id='content',
            exam_name='Sample Exam',
            time_limit_mins=10,
            is_proctored=True
        )

        if review_policy_exception:
            add_allowance_for_user(
                exam_id,
                self.user.id,
                ProctoredExamStudentAllowance.REVIEW_POLICY_EXCEPTION,
                review_policy_exception
            )

        policy = ProctoredExamReviewPolicy.objects.create(
            set_by_user_id=self.user.id,
            proctored_exam_id=exam_id,
            review_policy='Foo Policy'
        )

        test_self = self        # So that we can access test methods in nested function.

        def assert_get_payload_mock(self, exam, context):
            """
            Add a mock shim so we can assert that the _get_payload has been called with the right
            review policy
            """
            assert_get_payload_mock.called = True

            test_self.assertIn('review_policy', context)
            test_self.assertEqual(policy.review_policy, context['review_policy'])

            # call into real implementation
            # pylint: disable=too-many-function-args
            result = software_secure_get_payload(self, exam, context)

            # assert that this is in the 'reviewerNotes' field that is passed to SoftwareSecure
            expected = context['review_policy']
            if review_policy_exception:
                expected = '{base}; {exception}'.format(
                    base=expected,
                    exception=review_policy_exception
                )

            test_self.assertEqual(result['reviewerNotes'], expected)
            return result

        with HTTMock(mock_response_content):
            # patch the _get_payload method on the backend provider
            # so that we can assert that we are called with the review policy
            # as well as asserting that _get_payload includes that review policy
            # that was passed in
            with patch.object(SoftwareSecureBackendProvider, '_get_payload', assert_get_payload_mock):
                assert_get_payload_mock.called = False
                attempt_id = create_exam_attempt(
                    exam_id,
                    self.user.id,
                    taking_as_proctored=True
                )
                self.assertGreater(attempt_id, 0)

                # make sure we recorded the policy id at the time this was created
                attempt = get_exam_attempt_by_id(attempt_id)
                self.assertEqual(attempt['review_policy_id'], policy.id)
                self.assertTrue(assert_get_payload_mock.called)