Пример #1
0
 def put(self, questionID, answerID):
     # parser = reqparse.RequestParser()
     # parser.add_argument('downvote',
     #     type = str,
     #     required = True,
     #     help = "The upvote field is required"
     # )
     # data = parser.parse_args()
     question = QuestionModel.find_by_id(questionID)
     if question:
         answer = AnswerModel.find_by_id(questionID, answerID)
         if answer:
             answer.downvote(questionID)
             return {
                 "message": "Answer downvoted successfully"
             }, 201  #Created
         else:
             return {
                 "message": "Cannot downvote for a non-existing answer."
             }, 422  #Unprocessable entity
     else:
         return {
             "message":
             "Cannot downvote answer for a non-existing question."
         }, 422  #Unprocessable entity
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()
Пример #3
0
 def delete(self, questionID, answerID):
     question = QuestionModel.find_by_id(questionID)
     if question:
         answer = AnswerModel.find_by_id(questionID, answerID)
         if answer:
             answer.delete(questionID)
             return {"message": "Answer deleted successfully"}, 201
         else:
             return {
                 "message": "Answer already deleted or does not exist."
             }, 422
     else:
         return {
             "message": "Cannot delete answer for a non-existing question."
         }, 422
Пример #4
0
 def get(self, questionID, answerID):
     #Check if the question really exists
     #If True check for the answer and return
     #else, return a error message
     if QuestionModel.find_by_id(questionID):
         #Check for answer, returns an object
         answer = AnswerModel.find_by_id(questionID, answerID)
         if answer:
             return AnswerModel.find_descriptive_single_answer(
                 answerID), 200
         else:
             return {"message": "Answer not found."}, 422
     else:
         return {
             "message": "Cannot get answer for a non-existing question"
         }, 422
Пример #5
0
 def put(self, questionID, answerID):
     question = QuestionModel.find_by_id(questionID)
     if question:
         answer = AnswerModel.find_by_id(questionID, answerID)
         if answer:
             answer.upvote(questionID)
             return {
                 "message": "Answer upvoted successfully"
             }, 201  #Created
         else:
             return {
                 "message": "Cannot upvote for a non-existing answer."
             }, 422  #Unprocessable entity
     else:
         return {
             "message": "Cannot upvote answer for a non-existing question."
         }, 422  #Unprocessable entity
Пример #6
0
 def put(cls, questionID, answerID):
     data = cls.parser.parse_args()
     #check if the question exists
     #if exists, check for the answer
     #create a new answer object, update and return it
     #else return an error message
     if QuestionModel.find_by_id(questionID):
         answer = AnswerModel.find_by_id(questionID, answerID)
         if answer:
             answer.answer = data['answer']
             if answer.update(questionID):
                 return {"message": "Your answer updated successfully"}, 201
         else:
             return {"message": "Cannot update a non-existing answer."}, 422
     else:
         return {
             "message": "Cannot update answer for a non-existing question."
         }, 422
Пример #7
0
    def put(self, questionID, answerID):

        question = QuestionModel.find_by_id(questionID)
        if question:
            answer = AnswerModel.find_by_id(questionID, answerID)
            if answer:
                answer.solve(questionID)
                return {
                    "message": "Answer marked as solution successfully"
                }, 201  #Created
            else:
                return {
                    "message":
                    "Cannot mark a non-existing answer as a solution."
                }, 422  #Unprocessable entity
        else:
            return {
                "message": "Cannot solve a non-existing question."
            }, 422  #Unprocessable entity