Esempio n. 1
0
 def test_standard_review_mode_extra_rationales(self):
     """Test answering questions in default mode with extra rationales,
     with scoring enabled. Also testing shown rationales with no see more
     press."""
     self.set_question(
         factories.QuestionFactory(
             answer_style=Question.NUMERIC,
             choices=5,
             choices__correct=[2, 4],
             choices__rationales=6,
         ))
     self.mock_grade.return_value = Grade.INCORRECT
     self.run_standard_review_mode_extra_rationales()
     self.assert_grade_signal()
     self.assertTrue(self.mock_grade.called)
Esempio n. 2
0
 def test_numeric_answer_labels(self):
     """Test answering questions in default mode, using numerical labels."""
     self.set_question(
         factories.QuestionFactory(
             answer_style=Question.NUMERIC,
             choices=5,
             choices__correct=[2, 4],
             choices__rationales=4,
         ))
     self.EXPECTED_RESULT_COLUMNS = [
         {
             "name": "label",
             "label": "Choice"
         },
         {
             "name": "before",
             "label": "Before"
         },
         {
             "name": "after",
             "label": "After"
         },
         {
             "name": "to_1",
             "label": "To 1"
         },
         {
             "name": "to_2",
             "label": "To 2"
         },
         {
             "name": "to_3",
             "label": "To 3"
         },
         {
             "name": "to_4",
             "label": "To 4"
         },
         {
             "name": "to_5",
             "label": "To 5"
         },
     ]
     self.run_standard_review_mode()
Esempio n. 3
0
    def setUp(self):
        super(QuestionViewTestCase, self).setUp()

        UsesCriterion.objects.filter(
            quality__quality_type__type="global").delete()

        # TOS integration
        from tos.models import Consent, Role, Tos

        role = Role.objects.get(role="student")

        tos = Tos(version=1, text="Test", current=True, role=role)
        tos.save()
        no_share_user = User(username="******", email="*****@*****.**")
        no_share_user.save()
        # To test latest consent is used
        consent = Consent(user=no_share_user,
                          accepted=True,
                          tos=Tos.objects.first())
        consent.save()
        no_consent = Consent(user=no_share_user,
                             accepted=False,
                             tos=Tos.objects.first())
        no_consent.save()

        self.user = factories.UserFactory()
        self.assignment = factories.AssignmentFactory()
        self.set_question(
            factories.QuestionFactory(choices=5,
                                      choices__correct=[2, 4],
                                      choices__rationales=4))
        self.add_user_to_even_answers()
        self.addCleanup(mock.patch.stopall)
        signal_patcher = mock.patch(
            "django_lti_tool_provider.signals.Signals.Grade.updated.send")
        self.mock_send_grade_signal = signal_patcher.start()
        grade_patcher = mock.patch("peerinst.models.Answer.grade",
                                   new_callable=mock.PropertyMock)
        self.mock_grade = grade_patcher.start()
        self.mock_grade.return_value = Grade.CORRECT
Esempio n. 4
0
    def test_sequential_review_mode(self):
        """Test answering questions in sequential review mode."""

        self.mock_grade.return_value = Grade.INCORRECT

        self.set_question(
            factories.QuestionFactory(
                sequential_review=True,
                choices=5,
                choices__correct=[2, 4],
                choices__rationales=4,
            ))

        # Show the question and the form for the first answer and rationale.
        response = self.question_get()
        self.assertTemplateUsed(response, "peerinst/question/start.html")
        self.assertEqual(response.context["assignment"], self.assignment)
        self.assertEqual(response.context["question"], self.question)
        self.assertEqual(response.context["answer_choices"],
                         self.answer_choices)

        # Provide a first answer and a rationale.
        first_answer_choice = 2
        first_choice_label = self.question.get_choice_label(2)
        rationale = "my rationale text"
        response = self.question_post(first_answer_choice=first_answer_choice,
                                      rationale=rationale)

        # Loop over all rationales and vote on them.
        votes = []
        while "peerinst/question/sequential_review.html" in (
                template.name for template in response.templates):
            self.assertTrue(response.context["current_rationale"])
            vote = random.choice(["upvote", "downvote"])
            votes.append(vote)
            response = self.question_post(**{vote: 1})

        # We've reached the final review.
        self.assertTemplateUsed(response, "peerinst/question/review.html")
        self.assertEqual(response.context["assignment"], self.assignment)
        self.assertEqual(response.context["question"], self.question)
        self.assertEqual(response.context["answer_choices"],
                         self.answer_choices)
        self.assertEqual(response.context["first_choice_label"],
                         first_choice_label)
        self.assertEqual(response.context["rationale"], rationale)
        self.assertEqual(response.context["sequential_review"], True)
        stage_data = SessionStageData(self.client.session, self.custom_key)
        rationale_choices = stage_data.get("rationale_choices")
        second_answer_choices = [
            choice
            for choice, unused_label, unused_rationales in rationale_choices
        ]
        self.assertIn(first_answer_choice, second_answer_choices)

        # Select a different answer during review.
        second_answer_choice = next(choice for choice in second_answer_choices
                                    if choice != first_answer_choice)
        second_choice_label = self.question.get_choice_label(
            second_answer_choice)
        chosen_rationale = int(rationale_choices[1][2][0][0])
        response = self.question_post(
            second_answer_choice=second_answer_choice,
            rationale_choice_1=chosen_rationale,
        )
        self.assertTemplateUsed(response, "peerinst/question/summary.html")
        self.assertEqual(response.context["assignment"], self.assignment)
        self.assertEqual(response.context["question"], self.question)
        self.assertEqual(response.context["answer_choices"],
                         self.answer_choices)
        self.assertEqual(response.context["first_choice_label"],
                         first_choice_label)
        self.assertEqual(response.context["second_choice_label"],
                         second_choice_label)
        self.assertEqual(response.context["rationale"], rationale)
        self.assertEqual(response.context["chosen_rationale"].id,
                         chosen_rationale)

        answer = Answer.objects.get(
            question=self.question,
            assignment=self.assignment,
            first_answer_choice=first_answer_choice,
            rationale=rationale,
        )
        shown_rationales = [
            Answer.objects.get(id=_rationale[0]) if _rationale[0] else None
            for _, _, rationales in rationale_choices
            for _rationale in rationales[:2]
        ]
        for _rationale in shown_rationales:
            try:
                ShownRationale.objects.get(shown_for_answer=answer,
                                           shown_answer=_rationale)
            except ShownRationale.DoesNotExist:
                assert False

        self.assert_grade_signal()
        self.assertTrue(self.mock_grade.called)