def test_add_non_man_question(self):
     c.question('Test non-man Q', [], 0, 1)
     question_id = self.controller.question_id('Test non-man Q')
     question = f.find_question(question_id)
     self.assertEqual(question.text, 'Test non-man Q')
     self.assertEqual(question.mandatory, 0)
     self.assertEqual(question.mcq, 1)
def add_questions():

    flag = False
    if not current_user.is_authenticated or current_user.role != "admin":
        return redirect('/login/add_questions')

    # triggers when the user presses a button
    # either 'add question' or 'preview questions'
    if request.method == "POST":

        # if user requests a preview of questions
        if "preview" in request.form:
            # redirect to preview page
            return redirect(url_for('preview', back=1, user=current_user))

        # if user has requested to add a question
        elif "question_bt" in request.form:
            text = request.form['question']
            notype1 = request.form.get('type1') is None
            notype2 = request.form.get('type1') is None
            if len(text) == 0 or notype1 or notype2:
                flag = True
            else:
                mandatory, mcq = request.form['type1'], request.form['type2']
                create.question(text, f.get_pool_text(), mandatory, mcq)

    # reload page retaining appropriate selected values
    return render_template('add.html', user=current_user, flag=flag)
 def test_add_man_text_question(self):
     c.question('Test text Q', [], 1, 0)
     question_id = self.controller.question_id('Test text Q')
     question = f.find_question(question_id)
     self.assertEqual(question.text, 'Test text Q')
     self.assertEqual(question.mandatory, 1)
     self.assertEqual(question.mcq, 0)
 def test_create_survey_with_course_that_doesnt_exist(self):
     c.question('Test1', [], 1, 1)
     c.question('Test2', [], 0, 1)
     q_id1 = self.controller.question_id('Test1')
     q_id2 = self.controller.question_id('Test2')
     with self.assertRaises(IndexError):
         c.survey([q_id1, q_id2], 'COMP9999', '99s2', 'Test Survey', '')
 def test_create_survey_without_course(self):
     c.question('Test1', [], 1, 1)
     c.question('Test2', [], 0, 1)
     q_id1 = self.controller.question_id('Test1')
     q_id2 = self.controller.question_id('Test2')
     with self.assertRaises(TypeError):
         c.survey([q_id1, q_id2], 'Test Survey', '')
 def setUp(self):
     drop_tables()
     initialiseDB()
     self.controller = m.Controller()
     c.question('Test1', [], 1, 1)
     c.question('Test2', [], 0, 1)
     q_id1 = self.controller.question_id('Test1')
     q_id2 = self.controller.question_id('Test2')
     self.controller.model.add_course('COMP1531', '17s2')
     c.survey([q_id1, q_id2], 'COMP1531', '17s2', 'Test Survey', '')
    def test_create_survey(self):
        c.question('Test1', [], 1, 1)
        c.question('Test2', [], 0, 1)
        q_id1 = self.controller.question_id('Test1')
        q_id2 = self.controller.question_id('Test2')
        self.controller.model.add_course('COMP1531', '17s2')
        c.survey([q_id1, q_id2], 'COMP1531', '17s2', 'Test Survey', '')
        course_id = self.controller.model.course_id('COMP1531', '17s2')
        survey_id = self.controller.model.survey_id('Test Survey', course_id)
        survey = f.find_survey(survey_id)
        survey_qs = self.controller.model.survey_questions(course_id)
        question1 = f.find_question(survey_qs[0][0])
        question2 = f.find_question(survey_qs[1][0])

        self.assertEqual(survey.title, 'Test Survey')
        self.assertEqual(question1.text, 'Test1')
        self.assertEqual(question2.text, 'Test2')
 def test_add_question_with_no_mcq(self):
     with self.assertRaises(TypeError):
         c.question('Test 4', [], 1)
 def test_add_question_with_no_mandatory(self):
     with self.assertRaises(TypeError):
         c.question('Test 3', [], 1)
 def test_add_question_with_no_text_list(self):
     with self.assertRaises(TypeError):
         c.question('Test 2', 1, 1)
 def test_add_question_with_no_q_name(self):
     with self.assertRaises(TypeError):
         c.question([], 1, 1)