def test_question_text_not_null(self): try: Question.create(theory=self.theory, text=None) except IntegrityError: assert True else: assert False
def question_publish(): form = request.form question = Question(form) u = current_user() question.user_id = u.id question.save() red.incr('question') return redirect( url_for('.question_all', n_id=question.node_id, t_id=question.topic_id))
def add_question(): questionText = request.json['questionText'] questionId = request.json['questionId'] new_question = Question(questionText, questionId) db.session.add(new_question) db.session.commit() return question_schema.jsonify(new_question)
class Test_ModelQuestion: def setup_class(self): self.theory = Theory(theme='test text', text='test text') self.question = Question(theory=self.theory, text='That is text') def teardown_class(self): self.theory.delete_instance() self.question.delete_instance() def test_theory_in_question_is_theory(self): assert self.theory is self.question.theory def test_question_text(self): assert self.question.text == 'That is text' def test_question_text_not_null(self): try: Question.create(theory=self.theory, text=None) except IntegrityError: assert True else: assert False
class Test_ModelAnswer: def setup_class(self): self.theory = Theory(theme='lala', text='rur') self.question = Question(theory=self.theory, text='is it test?') self.right_answer = Answer(question=self.question, text='right', is_right=True) self.false_answer = Answer(question=self.question, text='false', is_right=False) self.default_answer = Answer(question=self.question, text='default') def teardown_class(self): self.theory.delete_instance() self.question.delete_instance() self.right_answer.delete_instance() self.false_answer.delete_instance() def test_right_answer(self): assert self.right_answer.is_right def test_fasle_answer(self): assert not self.false_answer.is_right def test_texts_answer(self): assert self.right_answer.text == 'right' assert self.false_answer.text == 'false' def test_question_from_answers_is_question(self): assert self.right_answer.question is self.question assert self.false_answer.question is self.question def test_answer_text_is_none(self): try: Answer.create(question=self.question, text=None, is_right=False) except IntegrityError: assert True else: assert False def test_is_right_default_position(self): assert not self.default_answer.is_right
def create_questions(): try: body = request.get_json() new_q = body.get("question") new_answer = body.get("answer") new_difficulty = body.get("difficulty") new_category = body.get("category") question = Question( question=new_q, answer=new_answer, difficulty=new_difficulty, category=new_category, ) question.insert() return jsonify({ "success": True, }) except AttributeError: abort(422)
def grab_questions(sessions, verify): """queries github pages for questions""" questions = [] for sess_no in sessions: url = '{1}Session{0}/session_{0}_problems.json'.format( sess_no, ROOT_URL) resp = requests.get(url, verify=verify).text print resp resp = json.loads(resp) for question in resp: questions.append( Question(name=question['name'], question=question['question'], function_name=question['function_name'], answer=question['answers'], args=question['args'], timeout=question['timeout'], session=sess_no)) return questions
def grab_questions(sessions, verify): """queries github pages for questions""" questions = [] for sess_no in sessions: url = '{1}Session{0}/session_{0}_problems.json'.format( sess_no, 'https://raw.githubusercontent.com/ArupAus/lunchtimepython/2017/') resp = requests.get(url, verify=verify).text resp = json.loads(resp) for question in resp: questions.append( Question(name=question['name'], question=question['question'], function_name=question['function_name'], answer=question['answers'], args=question['args'], timeout=question['timeout'], session=sess_no)) return questions
def setup_class(self): self.theory = Theory(theme='test text', text='test text') self.question = Question(theory=self.theory, text='That is text')
def setup_class(self): self.theory = Theory(theme='lala', text='rur') self.question = Question(theory=self.theory, text='is it test?') self.right_answer = Answer(question=self.question, text='right', is_right=True) self.false_answer = Answer(question=self.question, text='false', is_right=False) self.default_answer = Answer(question=self.question, text='default')