コード例 #1
0
 def test_save_is_correct(self):
     q = factories.Question(
         question_type=Question.QuestionType.SINGLE_ANSWER)
     a = factories.TextAnswer(question=q, is_correct=False)
     self.assertTrue(a.is_correct)
     q = factories.Question(
         question_type=Question.QuestionType.MULTIPLE_CHOICE)
     a = factories.TextAnswer(question=q, is_correct=False)
     self.assertFalse(a.is_correct)
コード例 #2
0
    def test_multiple_choice(self):
        question = factories.Question(
            question_type=Question.QuestionType.MULTIPLE_CHOICE,
            answer_type=Question.AnswerType.TEXT,
        )
        a1 = factories.TextAnswer(question=question,
                                  content__text='One',
                                  is_correct=True)
        a2 = factories.TextAnswer(question=question, content__text='Two')
        a3 = factories.TextAnswer(question=question, content__text='Three')
        a4 = factories.TextAnswer(question=question, content__text='Four')
        wrong_responses = [
            UserResponse.objects.create(
                profile=profile_factories.User().profile,
                question=question,
                content=a,
            ) for a in [a2, a3, a4]
        ]
        right_response = UserResponse.objects.create(
            profile=profile_factories.User().profile,
            question=question,
            content=a1,
        )
        for r in wrong_responses:
            self.assertFalse(r.check_response())
            self.assertFalse(r.is_correct)
            self.assertIsNotNone(r.answered_on)

        self.assertTrue(right_response.check_response())
        self.assertTrue(right_response.is_correct)
        self.assertIsNotNone(right_response.answered_on)
コード例 #3
0
 def test_question_type_switch_no_answer(self):
     q = factories.Question(
         answer_type=Question.AnswerType.TEXT,
         question_type=Question.QuestionType.MULTIPLE_CHOICE,
     )
     q.question_type = Question.QuestionType.SINGLE_ANSWER
     q.save()
     q.refresh_from_db()
     self.assertEqual(q.question_type, Question.QuestionType.SINGLE_ANSWER)
コード例 #4
0
 def test_get_correct(self):
     q = factories.Question(
         question_type=Question.QuestionType.MULTIPLE_CHOICE)
     with self.assertRaises(Answer.DoesNotExist):
         q.answers.get_correct()
     a = factories.TextAnswer(question=q, is_correct=False)
     with self.assertRaises(Answer.DoesNotExist):
         q.answers.get_correct()
     a = factories.TextAnswer(question=q, is_correct=True)
     self.assertEqual(a, q.answers.get_correct())
コード例 #5
0
 def setUp(self):
     super(QuestionViewSetTests, self).setUp()
     self.question = factories.Question(
         question_type=Question.QuestionType.SINGLE_ANSWER,
         answer_type=Question.AnswerType.VECTOR
     )
     self.answer = factories.VectorAnswer(
         question=self.question,
         content=factories.AngleVector(angle=90)
     )
     self.url = '/api/v1/curricula/questions/{}/response'
コード例 #6
0
 def test_answer_type_switch(self):
     q = factories.Question(
         answer_type=Question.AnswerType.TEXT,
         question_type=Question.QuestionType.MULTIPLE_CHOICE)
     factories.TextAnswer.create_batch(4, question=q)
     self.assertEqual(q.answers.count(), 4)
     q.answer_type = Question.AnswerType.TEXT
     q.save()
     self.assertEqual(q.answers.count(), 4)
     q.answer_type = Question.AnswerType.VECTOR
     q.save()
     self.assertFalse(q.answers.exists())
コード例 #7
0
 def test_question_type_switch(self):
     q = factories.Question(
         answer_type=Question.AnswerType.TEXT,
         question_type=Question.QuestionType.MULTIPLE_CHOICE,
     )
     # create sequentially to have positions assigned properly.
     factories.TextAnswer(question=q, position=0)
     factories.TextAnswer(question=q, position=1)
     factories.TextAnswer(question=q, position=2)
     factories.TextAnswer(question=q, position=3)
     self.assertEqual(q.answers.count(), 4)
     q.question_type = Question.QuestionType.MULTIPLE_CHOICE
     q.save()
     self.assertEqual(q.answers.count(), 4)
     q.question_type = Question.QuestionType.SINGLE_ANSWER
     q.save()
     self.assertEqual(q.answers.count(), 1)
     a = q.answers.first()
     self.assertTrue(a.is_correct)
コード例 #8
0
 def test_single_answer(self):
     question = factories.Question(
         question_type=Question.QuestionType.SINGLE_ANSWER,
         answer_type=Question.AnswerType.VECTOR,
     )
     factories.VectorAnswer(question=question, content__angle=90)
     wrong = factories.Vector(angle=10)
     right = factories.Vector(angle=90)
     wrong_response = UserResponse.objects.create(
         profile=profile_factories.User().profile,
         question=question,
         content=wrong)
     self.assertFalse(wrong_response.check_response())
     self.assertFalse(wrong_response.is_correct)
     self.assertIsNotNone(wrong_response.answered_on)
     right_response = UserResponse.objects.create(
         profile=profile_factories.User().profile,
         question=question,
         content=right)
     self.assertTrue(right_response.check_response())
     self.assertTrue(right_response.is_correct)
     self.assertIsNotNone(right_response.answered_on)