예제 #1
0
def get_next_question():
    if questions and len(questions):
        quest = str(Questions.get_question_raw_json(questions))
        quest = eval(quest)
        return render_template(
            'question.html',
            title="QUIZ",
            order=quest['order'],
            question_text=quest["question_text"],
            type=quest['answers']['type'],
            answers=quest['answers']['answer'],
            category=quest['category'],
            correct=quest['answers']['correct'],
            remain=len(questions),
        )
    else:
        rq = Questions()
        total = rq.final_tally(session['scores'])
        cat_totals = rq.category_tally(session['scores'])
        cat_quest_numbers = Questions.get_number_of_questions_by_category(
            Questions.load_questions())
        return render_template('end_of_questions.html',
                               title="QUIZ",
                               total=total,
                               cat_totals=cat_totals,
                               num_per_cat=cat_quest_numbers)
예제 #2
0
 def test_final_tally(self, mock_get_points_per_question):
     results = {
         'results': [{
             "quest_num": 1,
             "result": 1,
             "correct": 1,
             "right_or_wrong": 1,
             "category": 'Monitoring and Reporting'
         }, {
             "quest_num": 2,
             "result": 2,
             "correct": 3,
             "right_or_wrong": 0,
             "category": 'Monitoring and Reporting'
         }, {
             "quest_num": 3,
             "result": 3,
             "correct": 3,
             "right_or_wrong": 1,
             "category": 'Monitoring and Reporting'
         }, {
             "quest_num": 4,
             "result": 1,
             "correct": 1,
             "right_or_wrong": 1,
             "category": 'Storage and Management'
         }, {
             "quest_num": 5,
             "result": 2,
             "correct": 3,
             "right_or_wrong": 0,
             "category": 'Storage and Management'
         }, {
             "quest_num": 6,
             "result": 3,
             "correct": 3,
             "right_or_wrong": 1,
             "category": 'Storage and Management'
         }]
     }
     rq = Questions()
     mock_get_points_per_question.return_value = 16.67
     final = rq.final_tally(results)
     exp_result = 66.68
     self.assertEqual(final, exp_result)