def put(self, question_id, answer_id):
        data = parser.parse_args()
        data['question_id'] = question_id

        answer = AnswerModel.find_by_id(answer_id)

        if answer is None:
            new_answer = AnswerModel(**data)
            try:
                new_answer.save()

                return new_answer.json(), 201
            except:
                return {
                    "message": "An error occurred while inserting Question."
                }, 500

        try:
            answer.update(**data)
        except:
            return {
                "message": "An error occurred while updating Question."
            }, 500

        return answer.json(), 200
 def test_2save(self):
     AnswerModel.save(101,1234,'TEST')
     obj = None
     try:
         obj = session.query(AnswerModel).filter_by(questionID=101,userID=1234).one()
     except:
         pass
     self.assertTrue(obj is not None)
 def test_1get_all(self):
     AnswerModel.save(100,1234,'TEST')
     obj = None
     try:
         obj = AnswerModel().get_all()
     except:
         pass
     self.assertTrue(obj is not None)
 def test_3by_ids(self):
     AnswerModel.save(101,1234,'TEST')
     ids = [1, 2]
     obj = None
     try:
         obj = AnswerModel().by_ids(ids)
     except:
         pass
     self.assertTrue(obj is not None)
Beispiel #5
0
    def save():
        try:
            questionid = int(request.values['questionid'])
            question = Question.by_id(questionid)
            text = request.values['text']
            userid = g.lti.get_user_id()
        except:
            return abort(404)

        if AnswerModel.question_valid(questionid) and text != "":
            AnswerModel.save(questionid, userid, text)

        return redirect('/index_student')
    def post(self, question_id):
        data = parser.parse_args()
        data['question_id'] = question_id

        answer = AnswerModel(**data)
        try:
            answer.save()
        except:
            return {
                "message": "An error occurred while inserting Question."
            }, 500

        return answer.json(), 201