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)
def test_category_tally(self, mock_get_points_per_question): mock_get_points_per_question.return_value = 16.67 exp_result = { 'Monitoring and Reporting': 33.34, 'Storage and Management': 33.34 } 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() cat_result = rq.category_tally(results) self.assertTrue(TestQuestions.compare_dict(exp_result, cat_result))