def test_sequence_of_the_mixed_type_fields_in_from_model_should_be_same_as_xlsform(self): parser = XlsFormParser(self.REPEAT, "My questionnaire") xls_parser_response = parser.parse() names = [f['code'] if f['type'] != 'field_set' else self._repeat_codes(f) for f in xls_parser_response.json_xform_data] expected_names = ['familyname', ['family',['name','age']], 'city', ['house',['name','room','numberofrooms']]] self.assertEqual(names, expected_names)
def test_should_not_populate_errors_when_choice_answer_has_no_media_present(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {u'name': u'tmpGX1Ud_', u'title': u'tmpGX1Ud_', u'sms_keyword': u'tmpGX1Ud_', u'default_language': u'default', u'id_string': u'tmpGX1Ud_', u'type': u'survey', u'children': [ {u'choices': [{u'name': u'crow', u'label': u'crow'}, {u'name': u'eagle', u'label': u'Eagle'}], u'label': u'What bird did you see?', u'type': u'select one', u'name': u'bird', u'hint': u'Some birds have included images or audio.'}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}]} get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', u'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, [])
def test_should_populate_error_when_settings_sheet_present_with_default_language(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {'children': [{u'bind': {u'required': u'no'}, u'type': u'text', u'name': u'college', u'label': u'College Name'}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}], 'title': 'asdasx', 'name': 'asdasx', 'id_string': 'asdasx', 'default_language': 'default_something' } get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, {"XLSForm settings worksheet and the related values in survey sheet."})
def test_should_populate_error_when_calculate_field_with_prefetch_present(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {'children': [ {u'bind': {u'calculate': u'pulldata(fruit, "mangoes")'}, u'type': u'calculate', u'name': u'calc', u'label': u'1. Are you a student?'}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}], 'title': 'asdasx', 'name': 'asdasx', 'id_string': 'asdasx', 'default_language': 'default' } get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, {"preloading of CSV data (the PullData() function)."})
def test_should_populate_error_when_choice_has_no_label(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {'children': [{u'bind': {u'required': u'yes'}, u'type': u'select one', u'name': u'is_student', u'label': u'1. Are you a student?', u'choices': [{u'name': u'yes'}, {u'name': u'no', u'label': u'No'}]}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}], 'title': 'asdasx', 'name': 'asdasx', 'id_string': 'asdasx', 'default_language': 'default' } get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, {"optional labels. Label is a mandatory field for choice option with name [yes]"})
def test_should_populate_error_when_media_type_present_as_a_data_type(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {u'children': [{u'name': u'bird', u'hint': u'Some birds have included images or audio.', u'media': {u'audio': u'question.wav'}, u'choices': [{u'name': u'eagle', u'label': u'Eagle'}], u'label': u'What bird did you see?', u'type': u'select one'}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}], u'type': u'repeat', u'name': u'myrepeat', u'label': u'My repeat', 'title': 'asdasx', 'name': 'asdasx', 'id_string': 'asdasx', 'default_language': 'default' } get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, {"XLSForm media type (audio) in survey sheet."})
def test_should_populate_error_when_unsupported_geoshape_question_present_within_a_repeat(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {u'children': [ {u'children': [ {u'bind': {u'required': u'yes'}, u'type': u'geoshape', u'name': u'timeq', u'label': u'Time q'}, {u'bind': {u'required': u'yes'}, u'type': u'datetime', u'name': u'datetq', u'label': u'Date time q'}], u'type': u'group', u'name': u'mygroup', u'label': u'My group' }], u'type': u'repeat', u'name': u'myrepeat', u'label': u'My repeat', 'title': 'asdasx', 'name': 'asdasx', 'id_string': 'asdasx', 'default_language': 'default' } get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, {"geoshape as a datatype"})
def test_should_populate_error_when_default_choice_name_not_in_choice_list(self): with patch('datawinners.blue.xform_bridge.parse_file_to_json') as get_xform_dict: fields = {'children': [{u'bind': {u'required': u'yes'}, u'type': u'select all that apply or specify other', 'default': "invalid", u'name': u'is_student', u'label': u'1. Are you a student?', u'choices': [{u'name': u'yes', u'label': 'yes'}, {u'name': u'no', u'label': u'No'}]}, {'control': {'bodyless': True}, 'type': 'group', 'name': 'meta', 'children': [ {'bind': {'readonly': 'true()', 'calculate': "concat('uuid:', uuid())"}, 'type': 'calculate', 'name': 'instanceID'}]}], 'title': 'asdasx', 'name': 'asdasx', 'id_string': 'asdasx', 'default_language': 'default' } get_xform_dict.return_value = fields xls_form_parser = XlsFormParser('some_path', 'questionnaire_name') xls_parser_response = xls_form_parser.parse() self.assertEquals(xls_parser_response.errors, { 'Entered default value is not defined in the choices list.'})