Ejemplo n.º 1
0
 def test_get_random(self):
     """Test the get_random method for the Question model."""
     with self.app_context:
         question = Question.get_random(self.c_1.id, [self.q_1.id])
         self.assertIsNone(question)
         question = Question.get_random(self.c_2.id, [self.q_2.id])
         self.assertIsNotNone(question)
         self.assertEqual(question, self.q_3.format())
Ejemplo n.º 2
0
    def quiz():
        data = request.get_json()
        previous_questions = data.get("previous_questions", [])
        category = data.get("quiz_category", None)

        if category is None:
            abort(400)

        question = Question.get_random(category["id"], previous_questions)

        if question is None:
            return jsonify({"success": True})

        return jsonify({"question": question, "success": True})