def test_subquestion_selection_in_form_question_creates_branch_flow(self):
     '''
     :return:
     '''
     q1 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1,
                                  identifier='test1',
                                  text='test1', answer_type=TextAnswer.choice_name())
     q2 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1,
                                  identifier='test2',
                                  text='test2', answer_type=TextAnswer.choice_name())
     q3 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1,
                                  identifier='test3',
                                  text='test3', answer_type=TextAnswer.choice_name())
     q4 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1,
                                  identifier='test4',
                                  text='test4', answer_type=TextAnswer.choice_name())
     q5 = Question.objects.create(qset_id=self.qset.id, response_validation_id=1,
                                  identifier='test5',
                                  text='test5', answer_type=TextAnswer.choice_name())
     self.batch.start_question = q1
     QuestionFlow.objects.create(question_id=q1.id, next_question_id=q3.id)
     QuestionFlow.objects.create(question_id=q3.id, next_question_id=q5.id)
     test_condition = TextAnswer.validators()[0].__name__
     test_param = 'Hey you!!'
     form_data = {
         'action': LogicForm.ASK_SUBQUESTION,
         'next_question': q4.pk,
         'condition': test_condition,
         'value': test_param
     }
     l = LogicForm(q1, 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=q1.id, next_question_id=q4.id)
             TextArgument.objects.get(flow=qf, param=test_param)
             qf = QuestionFlow.objects.get(
                 question_id=q1.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.assertTrue(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)
예제 #3
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_subquestion_selection_in_form_question_creates_branch_flow(self):
     '''
     :return:
     '''
     q1 = Question.objects.create(qset_id=self.qset.id,
                                  response_validation_id=1,
                                  identifier='test1',
                                  text='test1',
                                  answer_type=TextAnswer.choice_name())
     q2 = Question.objects.create(qset_id=self.qset.id,
                                  response_validation_id=1,
                                  identifier='test2',
                                  text='test2',
                                  answer_type=TextAnswer.choice_name())
     q3 = Question.objects.create(qset_id=self.qset.id,
                                  response_validation_id=1,
                                  identifier='test3',
                                  text='test3',
                                  answer_type=TextAnswer.choice_name())
     q4 = Question.objects.create(qset_id=self.qset.id,
                                  response_validation_id=1,
                                  identifier='test4',
                                  text='test4',
                                  answer_type=TextAnswer.choice_name())
     q5 = Question.objects.create(qset_id=self.qset.id,
                                  response_validation_id=1,
                                  identifier='test5',
                                  text='test5',
                                  answer_type=TextAnswer.choice_name())
     self.batch.start_question = q1
     QuestionFlow.objects.create(question_id=q1.id, next_question_id=q3.id)
     QuestionFlow.objects.create(question_id=q3.id, next_question_id=q5.id)
     test_condition = TextAnswer.validators()[0].__name__
     test_param = 'Hey you!!'
     form_data = {
         'action': LogicForm.ASK_SUBQUESTION,
         'next_question': q4.pk,
         'condition': test_condition,
         'value': test_param
     }
     l = LogicForm(q1, 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=q1.id,
                                           next_question_id=q4.id)
             TextArgument.objects.get(flow=qf, param=test_param)
             qf = QuestionFlow.objects.get(question_id=q1.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.assertTrue(False, 'Invalid form')