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_questions_by_category(self): data = [{ "order": "1", "category": "Monitoring and Reporting", }, { "order": "2", "category": "Monitoring and Reporting", }, { "order": "3", "category": "High Availability", }, { "order": "4", "category": "Deployment and Provisioning", }, { "order": "5", "category": "Deployment and Provisioning", }, { "order": "6", "category": "Storage and Data Management", }, { "order": "7", "category": "Storage and Data Management", }, { "order": "8", "category": "Storage and Data Management", }, { "order": "9", "category": "Security and Compliance", }, { "order": "10", "category": "Security and Compliance", }, { "order": "11", "category": "Security and Compliance", }, { "order": "12", "category": "Networking", }, { "order": "13", "category": "Networking", }, { "order": "14", "category": "Automation and Optimization", }, { "order": "15", "category": "Automation and Optimization", }, { "order": "16", "category": "Automation and Optimization", }, { "order": "17", "category": "Networking", }] exp_category_totals = { 'Monitoring and Reporting': 2, 'High Availability': 1, 'Deployment and Provisioning': 2, 'Storage and Data Management': 3, 'Security and Compliance': 3, 'Networking': 3, 'Automation and Optimization': 3 } category_totals = Questions.get_number_of_questions_by_category(data) self.assertTrue( TestQuestions.compare_dict(exp_category_totals, category_totals))