def save_questions(questions_yes, request): user = None if request.user.is_authenticated(): user = request.user for question, details in questions.items(): question_model = QuestionModel.get_by_question(question) if not question_model: populate_questions() question_model = QuestionModel.get_by_question(question) q = Question(question=question_model, user=user, session_key=request.session.session_key) if question in questions_yes: q.answer = True else: q.answer = False q.save()
def test_get_answered_questions(): user = User() user.username = u"test" user.set_password("test123") assert user.save() assert user._id q = Question() q.question = u"test" q.author = u"anon" q.answer = u"My Answer!" q.user = user.username assert q.save(validate=True) assert q._id user_from_db = User.one({'username': '******'}) assert user_from_db.answered_questions().count() == 1
def add_question(): try: # formData = Question(request.get_json().get('question'),request.get_json().get('answer'),request.get_json().get('category'),request.get_json().get('difficulty')) formData = Question('', '', 0, 0) formData.question = request.get_json().get('question') formData.category = request.get_json().get('category') formData.answer = request.get_json().get('answer') formData.difficulty = request.get_json().get('difficulty') #print(formData.question) if(formData.question and formData.answer and formData.category and formData.difficulty): Question.insert(formData) return jsonify({ 'success':True }) else: return jsonify({ 'success':False, 'message':'Check All required Fields' }) except Exception as e: print(e) abort(422)