예제 #1
0
    def test_check_answers(self):
        # user has no score yet
        self.assertIsNone(self.user.score)

        key = 'answer'
        answers = {
            key + str(question.id): question.answer
            for question in self.questions[:10]
        }
        questions, score = Question.check_answers(key, answers, self.user)
        self.assertEqual(score, 10)

        # check score table has been populated
        self.assertEqual(self.user.score.score, 10)
예제 #2
0
    def test_best_score_is_preserved(self):
        # this makes total score of 10
        self.test_check_answers()

        key = 'answer'
        answers = {
            key + str(question.id): 'wrong-answer'
            for question in self.questions[:10]
        }
        questions, score = Question.check_answers(key, answers, self.user)
        self.assertEqual(score, 0)

        # however the old score (higher) is preserved
        self.assertEqual(self.user.score.score, 10)
예제 #3
0
파일: quiz.py 프로젝트: annshress/movquiz
def home():
    context = dict(
        key_name='answer',
        form={},
        questions=Question.fetch_quiz()
    )
    if request.method == 'POST':
        answered_questions, score = Question.check_answers(key_name=context['key_name'],
                                                           answers=request.form,
                                                           current_user=current_user)
        context.update(dict(
            form=request.form,
            questions=answered_questions,
            show_answer=True,
            score=score
        ))
    return render_template('pages/movies.html', **context)