def test_save_answer(): create_tables() create_user() new_question = QuestionModel('My simple title', 'My simple question') new_question.save(1) samp_answer = AnswerModel("This is my sample answer") samp_answer.add_answer(1, 'lazarus') teardown()
def test_delete(): create_tables() create_user() new_question = QuestionModel('My simple title', 'My simple question') new_question.save(1) samp_answer = AnswerModel("This is my sample answer") samp_answer.add_answer(1, 'lazarus') answer = AnswerModel.find_by_id(1, 1) assert answer.delete(1) == True teardown()
def post(cls, questionID): #Check if the question exists #if True create an answer dictionary and pass it #to add_answer method in answermodel(return the response) #else return error messages data = cls.parser.parse_args() identity = 0 if current_identity.id: identity = current_identity.username if QuestionModel.find_by_id(questionID): if not AnswerModel.find_by_answer(questionID, data['answer']): answer = AnswerModel(data["answer"]) if answer.add_answer(questionID, identity): return {"message": "Answer inserted successfully"}, 201 return {"message": "The answer already exists"}, 409 return {"message": "You cannot answer a non-existing question"}, 422