def test_create_and_saving_question(self): first_question = Quiz() first_question.question = '2+2*0+1=1' first_question.answer = False first_question.save() second_question = Quiz() second_question.question = 'Tomatoes is vegetable' second_question.answer = False second_question.save() saved_question = Quiz.objects.all() self.assertEqual(saved_question.count(), 2) first_saved_question = saved_question[0] second_saved_question = saved_question[1] self.assertEqual(first_saved_question.question, '2+2*0+1=1') self.assertEqual(first_saved_question.answer, False) self.assertEqual(second_saved_question.question, 'Tomatoes is vegetable') self.assertEqual(second_saved_question.answer, False)
def test_answer_question_and_points_collect(self): first_question = Quiz() first_question.question = '2+2*0+1=1' first_question.answer = False first_question.wrong_ans = 0 first_question.correct_ans = 0 first_question.save() # 2 correct answer first_question.correct_ans += 1 first_question.correct_ans += 1 # 1 wrong answer first_question.wrong_ans += 1 first_question.save() saved_question = Quiz.objects.first() self.assertEqual(saved_question.correct_ans, 2) self.assertEqual(saved_question.wrong_ans, 1)