def test_get_by_id(self): """Test the get_by_id method for the Question model.""" with self.app_context: question = Question.get_by_id(self.q_1.id) self.assertIsNotNone(question) self.assertEqual(question.question, self.q_1.question) self.assertEqual(question.answer, self.q_1.answer) self.assertEqual(question.difficulty, self.q_1.difficulty) self.assertEqual(question.category_id, self.q_1.category_id)
def delete_question(question_id): question = Question.get_by_id(question_id) if question is None: abort(404) result = question.delete_record() if result["error"]: abort(500) questions = Question.get_by_page(request, QUESTIONS_PER_PAGE) return jsonify({ "deleted": question_id, "questions": questions, "total_questions": len(Question.get_all()), "success": True, })