def test_end_interview_selection_in_form_question_creates_flow_to_with_no_next_question(self): ''' :return: ''' yes = 'yes' no = 'no' q1 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test1', text='test1', answer_type=DateAnswer.choice_name()) q2 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test2', text='test2', answer_type=MultiChoiceAnswer.choice_name()) q_o1 = QuestionOption.objects.create(question_id=q2.id, text=yes, order=1) QuestionOption.objects.create(question_id=q2.id, text=no, order=2) q3 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test3', text='test3', answer_type=DateAnswer.choice_name()) q4 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test4', text='test4', answer_type=DateAnswer.choice_name()) q5 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test5', text='test5', answer_type=DateAnswer.choice_name()) self.batch.start_question = q1 QuestionFlow.objects.create(question_id=q1.id, next_question_id=q2.id) QuestionFlow.objects.create(question_id=q2.id, next_question_id=q3.id) QuestionFlow.objects.create(question_id=q3.id, next_question_id=q4.id) QuestionFlow.objects.create(question_id=q4.id, next_question_id=q5.id) test_condition = MultiChoiceAnswer.validators()[0].__name__ form_data = { 'action': LogicForm.END_INTERVIEW, 'condition': test_condition, 'option': q_o1.order } l = LogicForm(q2, data=form_data) if l.is_valid(): l.save() # now check if equivalent Question flow and test arguments were # created try: qf = QuestionFlow.objects.get( question_id=q2.id, next_question_id__isnull=True) TextArgument.objects.get(flow=qf, position=0, param=q_o1.order) QuestionFlow.objects.get( question_id=q1.id, next_question_id=q2.id) QuestionFlow.objects.get( question_id=q2.id, next_question_id=q3.id) self.assertTrue(True) return except QuestionFlow.DoesNotExist: self.assertTrue(False, 'flow not existing') pass except TextArgument: self.assertTrue(False, 'text agrunments not saved') pass else: self.assertFalse(False, 'Invalid form')
def test_answer_validators(self): validators = [ # supported validators 'starts_with', 'ends_with', 'equals', 'between', 'less_than', 'greater_than', 'contains', ] for func in Answer.validators(): self.assertIn(func.__name__, validators) # test Numeric Answer Validators validators = [ # supported validators 'equals', 'between', 'less_than', 'greater_than', ] for func in NumericalAnswer.validators(): self.assertIn(func.__name__, validators) # test Text Answer Validators validators = [ # supported validators 'starts_with', 'ends_with', 'equals', 'contains', ] for func in TextAnswer.validators(): self.assertIn(func.__name__, validators) # Multichoice validators = [ # supported validators 'equals', ] for func in MultiChoiceAnswer.validators(): self.assertIn(func.__name__, validators) # test Multiselect Answer Validators validators = [ # supported validators 'equals', 'contains', ] for func in MultiSelectAnswer.validators(): self.assertIn(func.__name__, validators) # test Date Answer Validators validators = [ # supported validators 'equals', 'between', 'less_than', 'greater_than', ] for func in DateAnswer.validators(): self.assertIn(func.__name__, validators) # GeoPoint Answer validators = [ # supported validators 'equals', ] for func in GeopointAnswer.validators(): self.assertIn(func.__name__, validators) # file answers should return no validators for answer_class in [VideoAnswer, AudioAnswer, ImageAnswer]: self.assertEquals(len(answer_class.validators()), 0)
def test_answer_validators(self): validators = [ # supported validators 'starts_with', 'ends_with', 'equals', 'between', 'less_than', 'greater_than', 'contains', ] for func in Answer.validators(): self.assertIn(func.__name__, validators) # test Numeric Answer Validators validators = [ # supported validators 'equals', 'between', 'less_than', 'greater_than', ] for func in NumericalAnswer.validators(): self.assertIn(func.__name__, validators) # test Text Answer Validators validators = [ # supported validators 'starts_with', 'ends_with', 'equals', 'contains', ] for func in TextAnswer.validators(): self.assertIn(func.__name__, validators) # Multichoice validators = [ # supported validators 'equals', ] for func in MultiChoiceAnswer.validators(): self.assertIn(func.__name__, validators) # test Multiselect Answer Validators validators = [ # supported validators 'equals', 'contains', ] for func in MultiSelectAnswer.validators(): self.assertIn(func.__name__, validators) # test Date Answer Validators validators = [ # supported validators 'equals', 'between', 'less_than', 'greater_than', ] for func in DateAnswer.validators(): self.assertIn(func.__name__, validators) # GeoPoint Answer validators = [ # supported validators 'equals', ] for func in GeopointAnswer.validators(): self.assertIn(func.__name__, validators) # file answers should return no validators for answer_class in [VideoAnswer, AudioAnswer, ImageAnswer]: self.assertEquals(len(answer_class.validators()), 0)
def test_end_interview_selection_in_form_question_creates_flow_to_with_no_next_question( self): ''' :return: ''' yes = 'yes' no = 'no' q1 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test1', text='test1', answer_type=DateAnswer.choice_name()) q2 = Question.objects.create( qset_id=self.qset.id, response_validation_id=1, identifier='test2', text='test2', answer_type=MultiChoiceAnswer.choice_name()) q_o1 = QuestionOption.objects.create(question_id=q2.id, text=yes, order=1) QuestionOption.objects.create(question_id=q2.id, text=no, order=2) q3 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test3', text='test3', answer_type=DateAnswer.choice_name()) q4 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test4', text='test4', answer_type=DateAnswer.choice_name()) q5 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1, identifier='test5', text='test5', answer_type=DateAnswer.choice_name()) self.batch.start_question = q1 QuestionFlow.objects.create(question_id=q1.id, next_question_id=q2.id) QuestionFlow.objects.create(question_id=q2.id, next_question_id=q3.id) QuestionFlow.objects.create(question_id=q3.id, next_question_id=q4.id) QuestionFlow.objects.create(question_id=q4.id, next_question_id=q5.id) test_condition = MultiChoiceAnswer.validators()[0].__name__ form_data = { 'action': LogicForm.END_INTERVIEW, 'condition': test_condition, 'option': q_o1.order } l = LogicForm(q2, data=form_data) if l.is_valid(): l.save() # now check if equivalent Question flow and test arguments were # created try: qf = QuestionFlow.objects.get(question_id=q2.id, next_question_id__isnull=True) TextArgument.objects.get(flow=qf, position=0, param=q_o1.order) QuestionFlow.objects.get(question_id=q1.id, next_question_id=q2.id) QuestionFlow.objects.get(question_id=q2.id, next_question_id=q3.id) self.assertTrue(True) return except QuestionFlow.DoesNotExist: self.assertTrue(False, 'flow not existing') pass except TextArgument: self.assertTrue(False, 'text agrunments not saved') pass else: self.assertFalse(False, 'Invalid form')