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 create_survey(): if not current_user.is_authenticated or current_user.role != "admin": return redirect('/login/create_survey') qs = { key: q.text for key, q in s.questions_list.items() if int(q.mandatory) == 1 } created, exists = True, False if request.method == "POST": created = get_selected() # fills in semesters after code selection if "course_selection" in request.form: semester_fill(s.selected[0]) if "create_survey_button" in request.form and created: code, sem = s.selected[0], s.selected[1] exists = f.survey_from_course(code, sem) != "not-found" q_list = request.form.getlist("available") title = request.form['title'] time = request.form['time'] correct_time = True try: time = int(time) if len(time) > 0 else time except: correct_time = False if not correct_time or len(q_list) <= 0 or not title: created = False elif not exists: create.survey(q_list, code, sem, title, time) # display course and corresponding questions return render_template('survey_creation.html', user=current_user, values=s.selected, displays=[s.display_courses, s.display_sems], questions=qs, created=created, exists=exists)
def test_create_survey_without_questions(self): self.controller.model.add_course('COMP1531', '17s2') with self.assertRaises(AssertionError): c.survey([], 'COMP1531', '17s2', 'Test Survey', '')