Ejemplo n.º 1
0
 def test_raises_error_if_condition_expression_nonsense(self):
     condition = 'value_15_1|;:_|key_16'
     with self.assertRaises(ConfigurationErrorInvalidCondition):
         QuestionnaireQuestion(self.parent_obj, {
             'keyword': 'key_15',
             'form_options': {
                 'conditions': [condition]
             }
         })
Ejemplo n.º 2
0
 def test_raises_error_if_condition_wrong_formatted(self):
     condition = 'foo'
     with self.assertRaises(ConfigurationErrorInvalidCondition):
         QuestionnaireQuestion(self.parent_obj, {
             'keyword': 'key_15',
             'form_options': {
                 'conditions': [condition]
             }
         })
Ejemplo n.º 3
0
 def test_raises_error_if_value_does_not_exist(self):
     condition = 'foo|True|key_16'
     with self.assertRaises(ConfigurationErrorInvalidCondition):
         QuestionnaireQuestion(self.parent_obj, {
             'keyword': 'key_15',
             'form_options': {
                 'conditions': [condition]
             }
         })
Ejemplo n.º 4
0
 def test_raises_error_if_questiongroup_condition_expression_nonsense(self):
     qg_condition = ';%.|foo'
     with self.assertRaises(
             ConfigurationErrorInvalidQuestiongroupCondition):
         QuestionnaireQuestion(
             self.parent_obj, {
                 'keyword': 'key_16',
                 'form_options': {
                     'questiongroup_conditions': [qg_condition]
                 }
             })
Ejemplo n.º 5
0
 def get_child(self, qg_keyword: str,
               keyword: str) -> QuestionnaireQuestion:
     return QuestionnaireQuestion(
         self.config.get_questiongroup_by_keyword(qg_keyword),
         {'keyword': keyword})
Ejemplo n.º 6
0
 def test_lookup_choices_boolean(self):
     q = QuestionnaireQuestion(self.parent_obj, {'keyword': 'key_14'})
     q.choices = ((True, 'Yes'), (False, 'No'))
     l = q.lookup_choices_labels_by_keywords([True])
     self.assertEqual(l, ['Yes'])
Ejemplo n.º 7
0
 def test_lookup_choices_integer(self):
     q = QuestionnaireQuestion(self.parent_obj, {'keyword': 'key_12'})
     q.choices = ((1, 'Low'), (2, 'High'))
     l = q.lookup_choices_labels_by_keywords([1])
     self.assertEqual(l, ['Low'])
Ejemplo n.º 8
0
 def test_raises_error_if_not_in_db(self):
     configuration = {"keyword": "bar"}
     with self.assertRaises(ConfigurationErrorNotInDatabase):
         QuestionnaireQuestion(self.parent_obj, configuration)
Ejemplo n.º 9
0
 def test_lookup_choices_lookups_many_choices(self):
     mock_Questiongroup = Mock()
     mock_Questiongroup.configuration_keyword = 'sample'
     q = QuestionnaireQuestion(mock_Questiongroup, {'keyword': 'key_14'})
     l = q.lookup_choices_labels_by_keywords(['value_14_1', 'value_14_2'])
     self.assertEqual(l, ['Value 14_1', 'Value 14_2'])
Ejemplo n.º 10
0
 def test_raises_error_if_key_not_string(self):
     configuration = {"keyword": ["bar"]}
     with self.assertRaises(ConfigurationErrorInvalidConfiguration):
         QuestionnaireQuestion(self.parent_obj, configuration)
Ejemplo n.º 11
0
 def test_raises_error_if_key_not_found(self):
     configuration = {}
     with self.assertRaises(ConfigurationErrorInvalidConfiguration):
         QuestionnaireQuestion(self.parent_obj, configuration)
Ejemplo n.º 12
0
 def test_lookup_choices_integer(self):
     q = QuestionnaireQuestion(self.parent_obj, {'keyword': 'key_12'})
     q.choices = ((1, 'Low'), (2, 'High'))
     l = q.lookup_choices_labels_by_keywords([1])
     self.assertEqual(l, ['Low'])
Ejemplo n.º 13
0
 def test_lookup_choices_boolean(self):
     q = QuestionnaireQuestion(self.parent_obj, {'keyword': 'key_14'})
     q.choices = ((True, 'Yes'), (False, 'No'))
     l = q.lookup_choices_labels_by_keywords([True])
     self.assertEqual(l, ['Yes'])
Ejemplo n.º 14
0
 def test_lookup_choices_lookups_many_choices(self):
     mock_Questiongroup = Mock()
     mock_Questiongroup.configuration_keyword = 'sample'
     q = QuestionnaireQuestion(mock_Questiongroup, {'keyword': 'key_14'})
     l = q.lookup_choices_labels_by_keywords(['value_14_1', 'value_14_2'])
     self.assertEqual(l, ['Value 14_1', 'Value 14_2'])