def test_should_populate_error_when_constraint_not_given_for_dw_idnr_question(self): with patch('datawinners.blue.xform_bridge.entity_type_already_defined') as is_entity_type_already_defined: with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') fields = [{u'name': u'my_unique', u'label': u'mu_uni', u'type': u'dw_idnr'}] get_xform_dict.return_value = fields is_entity_type_already_defined.return_value = True questions, errors, unique_id_errors = xls_form_parser._create_questions(fields) self.assertEqual(questions.__len__(), 0) self.assertEqual(errors, { u"The Identification Number Type (dw_idnr) is missing in the Constraints column. Please add the Identification Number Type and upload again. <a target='_blank'>Learn More</a> about how to manage Identification Numbers with XLSForms. "})
def test_should_not_create_question_for_select_that_are_only_labels(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') fields = [{u'control': {u'appearance': u'label'}, u'name': u'table_list_test_label', u'hint': u'Show only the labels of these options and not the inputs (type=select_one yes_no, appearance=label)', u'choices': [{u'name': u'yes', u'label': u'Yes'}, {u'name': u'no', u'label': u'No'}, {u'name': u'dk', u'label': u"Don't Know"}, {u'name': u'na', u'label': u'Not Applicable'}], u'label': u'Table', u'type': u'select one'}, {u'control': {u'appearance': u'list-nolabel'}, u'name': u'table_list_1', u'hint': u'Show only the inputs of these options and not the labels (type=select_one yes_no, appearance=list-nolabel)', u'choices': [{u'name': u'yes', u'label': u'Yes'}, {u'name': u'no', u'label': u'No'}, {u'name': u'dk', u'label': u"Don't Know"}, {u'name': u'na', u'label': u'Not Applicable'}], u'label': u'Q1', u'type': u'select one'}, {u'control': {u'appearance': u'list-nolabel'}, u'name': u'table_list_2', u'hint': u'Show only the inputs of these options and not the labels (type=select_one yes_no, appearance=list-nolabel)', u'choices': [{u'name': u'yes', u'label': u'Yes'}, {u'name': u'no', u'label': u'No'}, {u'name': u'dk', u'label': u"Don't Know"}, {u'name': u'na', u'label': u'Not Applicable'}], u'label': u'Question 2', u'type': u'select one'}, {'control': {'bodyless': True}}] questions, errors, unique_id_errors = xls_form_parser._create_questions(fields) self.assertEqual(questions.__len__(), 2) self.assertDictEqual(questions[0], {'code': u'table_list_1', 'title': u'Q1', 'required': False, 'parent_field_code': None, 'has_other': False, 'choices': [{'value': {'text': u'Yes', 'val': u'yes'}}, {'value': {'text': u'No', 'val': u'no'}}, {'value': {'text': u"Don't Know", 'val': u'dk'}}, {'value': {'text': u'Not Applicable', 'val': u'na'}}], 'is_entity_question': False, 'type': 'select1'}) self.assertDictEqual(questions[1], {'code': u'table_list_2', 'title': u'Question 2', 'required': False, 'parent_field_code': None, 'has_other': False, 'choices': [{'value': {'text': u'Yes', 'val': u'yes'}}, {'value': {'text': u'No', 'val': u'no'}}, {'value': {'text': u"Don't Know", 'val': u'dk'}}, {'value': {'text': u'Not Applicable', 'val': u'na'}}], 'is_entity_question': False, 'type': 'select1'})
def test_should_create_entity_question_for_dw_idnr_question(self): with patch('datawinners.blue.xform_bridge.entity_type_already_defined') as is_entity_type_already_defined: with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: manager = Mock(DatabaseManager) manager.view = Mock(View) manager.view.count_non_voided_entities_by_type = Mock( return_value=[Row({'key': ['clinic'], 'value': 10})]) xls_form_parser = XlsFormParser('some_path', 'questionnaire_name', dbm=manager) fields = [{u'name': u'my_unique', u'bind': {u'constraint': u'clinic'}, u'label': u'mu_uni', u'type': u'dw_idnr'}] get_xform_dict.return_value = fields is_entity_type_already_defined.return_value = True questions, errors, unique_id_errors = xls_form_parser._create_questions(fields) self.assertEqual(questions.__len__(), 1) self.assertDictEqual(questions[0], {'instruction': 'Answer must be a Identification Number', 'code': u'my_unique', 'title': u'mu_uni', 'required': False, 'parent_field_code': None, 'name': u'mu_uni', 'is_entity_question': True, 'type': 'unique_id', 'uniqueIdType': u'clinic'})
def test_should_create_additional_text_question_for_single_select_or_other_question(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') fields = [{u'choices': [{u'name': u'male', u'label': u'Male'}, {u'name': u'female', u'label': u'Female'}], u'type': u'select one or specify other', u'name': u'hh_user_gender', u'label': u'Sex'}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}] questions, errors, unique_id_errors = xls_form_parser._create_questions(fields) self.assertEqual(questions.__len__(), 2) self.assertDictEqual(questions[0], {'code': u'hh_user_gender', 'title': u'Sex', 'required': False, 'parent_field_code': None, 'has_other': True, 'choices': [{'value': {'text': u'Male', 'val': u'male'}}, {'value': {'text': u'Female', 'val': u'female'}}], 'is_entity_question': False, 'type': 'select1'}) self.assertDictEqual(questions[1], {'code': u'hh_user_gender_other', 'title': u'Sex_other', 'required': False, 'parent_field_code': None, 'name': u'Sex_other', 'instruction': 'Answer must be a word', 'is_entity_question': False, 'type': u'text'})