def test_simple_yes_or_no_question(self): x = SurveyReader(absolute_path(__file__, "yes_or_no_question.xls")) x_results = x.to_dict() expected_dict = [{ u'label': { u'english': u'have you had a good day today?' }, u'type': u'select one', u'name': u'good_day', u'choices': [{ u'label': { u'english': u'yes' }, u'name': u'yes' }, { u'label': { u'english': u'no' }, u'name': u'no' }] }] self.assertEqual(x_results[u"children"], expected_dict)
def test_table(self): x = SurveyReader(utils.path_to_text_fixture("simple_loop.xls")) expected_dict = { u'type': u'survey', u'name': 'simple_loop', u'children': [ { u'children': [ { u'type': u'integer', u'name': u'count', u'label': {u'English': u'How many are there in this group?'} } ], u'type': u'loop', u'name': u'my_table', u'columns': [ { u'name': u'col1', u'label': {u'English': u'Column 1'} }, { u'name': u'col2', u'label': {u'English': u'Column 2'} } ], u'label': {u'English': u'My Table'} }]} self.assertEqual(x.to_dict(), expected_dict)
def test_specify_other(self): excel_reader = SurveyReader("pyxform/tests/specify_other.xls") d = excel_reader.to_dict() survey = create_survey_element_from_dict(d) expected_dict = { u'name': 'specify_other', u'type': u'survey', u'children': [ { u'name': u'sex', u'label': {u'English': u'What sex are you?'}, u'type': u'select one', u'children': [ { u'name': u'male', u'label': {u'English': u'Male'} }, { u'name': u'female', u'label': {u'English': u'Female'} }, { u'name': u'other', u'label': u'Other' } ] }, { u'name': u'sex_other', u'bind': {u'relevant': u"selected(../sex, 'other')"}, u'label': u'Specify other.', u'type': u'text'} ] } self.assertEqual(survey.to_dict(), expected_dict)
def test_include_json(self): excel_reader = SurveyReader("pyxform/tests/include_json.xls") d = excel_reader.to_dict() survey_in = create_survey_element_from_dict(d) for k, v in survey_in.to_dict().items(): if k != "name": self.assertEqual(v, self.survey_out_dict[k])
def test_include_json(self): excel_reader = SurveyReader("pyxform/tests/include_json.xls") d = excel_reader.to_dict() survey_in = create_survey_element_from_dict(d) for k, v in survey_in.to_dict().items(): if k!="name": self.assertEqual(v, self.survey_out_dict[k])
def test_include(self): excel_reader = SurveyReader("pyxform/tests/include.xls") d = excel_reader.to_dict() survey = create_survey_element_from_dict(d) expected_dict = { u'name': 'include', u'type': u'survey', u'children': [ { u'name': u'name', u'label': {u'English': u"What's your name?"}, u'type': u'text' }, { u'name': u'good_day', u'label': {u'english': u'have you had a good day today?'}, u'type': u'select one', u'children': [ { u'name': u'yes', u'label': {u'english': u'yes'} }, { u'name': u'no', u'label': {u'english': u'no'} } ]}]} self.assertEqual(survey.to_dict(), expected_dict)
def test_json(self): x = SurveyReader("pyxform/tests/group.xls") x_results = x.to_dict() expected_dict = { u'name': 'group', u'type': u'survey', u'children': [ { u'name': u'family_name', u'type': u'text', u'label': {u'English': u"What's your family name?"} }, { u'name': u'father', u'type': u'group', u'label': {u'English': u'Father'}, u'children': [ { u'name': u'phone_number', u'type': u'phone number', u'label': {u'English': u"What's your father's phone number?"} }, { u'name': u'age', u'type': u'integer', u'label': {u'English': u'How old is your father?'} } ], } ], } self.assertEqual(x_results, expected_dict)
def process_xls_io_to_section_json(file_io): # I agree that this function is not pretty, but I don't think we # should move this into the model because I prefer to think of the # model as file-format independent. path = save_in_temp_dir(file_io) m = re.search(r'([^/]+).xls$', path) slug = m.group(1) xlr = SurveyReader(path) xls_vals = xlr.to_dict() qjson = json.dumps(xls_vals) os.remove(path) return (slug, qjson)
def test_text_and_integer(self): x = SurveyReader(absolute_path(__file__, "text_and_integer.xls")) expected_dict = [{ u'text': { u'english': u'What is your name?' }, u'type': u'text', u'name': u'your_name' }, { u'text': { u'english': u'How many years old are you?' }, u'type': u'integer', u'name': u'your_age' }] self.assertEqual(x.to_dict()[u"children"], expected_dict)
def setUp(self): self.excel_files = [ "gps.xls", "include.xls", "specify_other.xls", "group.xls", "loop.xls", "text_and_integer.xls", # todo: this file uses json that was written in # builder_tests.py this needs to be fixed. # "include_json.xls", "simple_loop.xls", "yes_or_no_question.xls", ] self.surveys = {} for filename in self.excel_files: path = "pyxform/tests/%s" % filename excel_reader = SurveyReader(path) d = excel_reader.to_dict() self.surveys[filename] = create_survey_element_from_dict(d)
def test_specify_other(self): excel_reader = SurveyReader("pyxform/tests/specify_other.xls") d = excel_reader.to_dict() survey = create_survey_element_from_dict(d) expected_dict = { u'name': 'specify_other', u'type': u'survey', u'children': [{ u'name': u'sex', u'label': { u'English': u'What sex are you?' }, u'type': u'select one', u'children': [{ u'name': u'male', u'label': { u'English': u'Male' } }, { u'name': u'female', u'label': { u'English': u'Female' } }, { u'name': u'other', u'label': u'Other' }] }, { u'name': u'sex_other', u'bind': { u'relevant': u"selected(../sex, 'other')" }, u'label': u'Specify other.', u'type': u'text' }] } self.assertEqual(survey.to_dict(), expected_dict)
def test_simple_yes_or_no_question(self): x = SurveyReader(utils.path_to_text_fixture("yes_or_no_question.xls")) x_results = x.to_dict() expected_dict = [ { u'label': {u'english': u'have you had a good day today?'}, u'type': u'select one', u'name': u'good_day', u'choices': [ { u'label': {u'english': u'yes'}, u'name': u'yes' }, { u'label': {u'english': u'no'}, u'name': u'no' } ] } ] self.assertEqual(x_results[u"children"], expected_dict)
def test_include(self): excel_reader = SurveyReader("pyxform/tests/include.xls") d = excel_reader.to_dict() survey = create_survey_element_from_dict(d) expected_dict = { u'name': 'include', u'type': u'survey', u'children': [{ u'name': u'name', u'label': { u'English': u"What's your name?" }, u'type': u'text' }, { u'name': u'good_day', u'label': { u'english': u'have you had a good day today?' }, u'type': u'select one', u'children': [{ u'name': u'yes', u'label': { u'english': u'yes' } }, { u'name': u'no', u'label': { u'english': u'no' } }] }] } self.assertEqual(survey.to_dict(), expected_dict)
def test_table(self): x = SurveyReader(absolute_path(__file__, "simple_loop.xls")) expected_dict = { u'type': u'survey', u'name': 'simple_loop', u'children': [{ u'children': [{ u'type': u'integer', u'name': u'count', u'label': { u'English': u'How many are there in this group?' } }], u'type': u'loop', u'name': u'my_table', u'columns': [{ u'name': u'col1', u'label': { u'English': u'Column 1' } }, { u'name': u'col2', u'label': { u'English': u'Column 2' } }], u'label': { u'English': u'My Table' } }] } self.assertEqual(x.to_dict(), expected_dict)
def test_equality_of_to_dict(self): x = SurveyReader("pyxform/tests/group.xls") x_results = x.to_dict() survey_object = create_survey_element_from_dict(x_results) self.assertEqual(x_results, survey_object.to_dict())
def test_loop(self): excel_reader = SurveyReader("pyxform/tests/loop.xls") d = excel_reader.to_dict() survey = create_survey_element_from_dict(d) expected_dict = { u'name': 'loop', u'type': u'survey', u'children': [{ u'name': u'available_toilet_types', u'label': { u'english': u'What type of toilets are on the premises?' }, u'type': u'select all that apply', u'bind': { u'constraint': u"(.='none' or not(selected(., 'none')))" }, u'children': [ { u'name': u'pit_latrine_with_slab', u'label': { u'english': u'Pit latrine with slab' } }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' } }, { u'name': u'bucket_system', u'label': { u'english': u'Bucket system' } }, { u'name': u'none', u'label': u'None', }, { u'name': u'other', u'label': u'Other' }, ] }, { u'name': u'available_toilet_types_other', u'bind': { u'relevant': u"selected(../available_toilet_types, 'other')" }, u'label': u'Specify other.', u'type': u'text' }, { u'name': u'pit_latrine_with_slab', u'label': { u'english': u'Pit latrine with slab' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Pit latrine with slab are on the premises?' }, u'type': u'integer' }] }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Pit latrine without slab/open pit are on the premises?' }, u'type': u'integer' }] }, { u'name': u'bucket_system', u'label': { u'english': u'Bucket system' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Bucket system are on the premises?' }, u'type': u'integer' }] }, { u'name': u'other', u'label': u'Other', u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Other are on the premises?' }, u'type': u'integer' }] }] } self.assertEqual(survey.to_dict(), expected_dict)
def test_loop(self): excel_reader = SurveyReader("pyxform/tests/loop.xls") d = excel_reader.to_dict() survey = create_survey_element_from_dict(d) expected_dict = { u'name': 'loop', u'type': u'survey', u'children': [ { u'name': u'available_toilet_types', u'label': {u'english': u'What type of toilets are on the premises?'}, u'type': u'select all that apply', u'bind': {u'constraint': u"(.='none' or not(selected(., 'none')))"}, u'children': [ { u'name': u'pit_latrine_with_slab', u'label': {u'english': u'Pit latrine with slab'} }, { u'name': u'open_pit_latrine', u'label': {u'english': u'Pit latrine without slab/open pit'} }, { u'name': u'bucket_system', u'label': {u'english': u'Bucket system'} }, { u'name': u'none', u'label': u'None', }, { u'name': u'other', u'label': u'Other' }, ] }, { u'name': u'available_toilet_types_other', u'bind': {u'relevant': u"selected(../available_toilet_types, 'other')"}, u'label': u'Specify other.', u'type': u'text' }, { u'name': u'pit_latrine_with_slab', u'label': {u'english': u'Pit latrine with slab'}, u'type' : u'group', u'children': [ { u'name': u'number', u'label': {u'english': u'How many Pit latrine with slab are on the premises?'}, u'type': u'integer' }]}, { u'name': u'open_pit_latrine', u'label': {u'english': u'Pit latrine without slab/open pit'}, u'type' : u'group', u'children': [ { u'name': u'number', u'label': {u'english': u'How many Pit latrine without slab/open pit are on the premises?'}, u'type': u'integer' } ] }, { u'name': u'bucket_system', u'label': {u'english': u'Bucket system'}, u'type' : u'group', u'children': [ { u'name': u'number', u'label': {u'english': u'How many Bucket system are on the premises?'}, u'type': u'integer' } ] }, { u'name': u'other', u'label': u'Other', u'type' : u'group', u'children': [{u'name': u'number', u'label': {u'english': u'How many Other are on the premises?'}, u'type': u'integer'}]}]} self.assertEqual(survey.to_dict(), expected_dict)
def test_gps(self): x = SurveyReader(absolute_path(__file__, "gps.xls")) expected_dict = [{u'type': u'gps', u'name': u'location'}] self.assertEqual(x.to_dict()[u"children"], expected_dict)
def test_text_and_integer(self): x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls")) expected_dict = [{u'text': {u'english': u'What is your name?'}, u'type': u'text', u'name': u'your_name'}, {u'text': {u'english': u'How many years old are you?'}, u'type': u'integer', u'name': u'your_age'}] self.assertEqual(x.to_dict()[u"children"], expected_dict)
def test_gps(self): x = SurveyReader(utils.path_to_text_fixture("gps.xls")) expected_dict = [{u'type': u'gps', u'name': u'location', u'label': u'GPS'}] self.assertEqual(x.to_dict()[u"children"], expected_dict)
def test_gps(self): x = SurveyReader(absolute_path(__file__, "gps.xls")) expected_dict = [{u'type': u'gps', u'name': u'location'}] self.assertEqual(x.to_dict()[u"children"], expected_dict)
def test_equality_of_to_dict(self): x = SurveyReader(utils.path_to_text_fixture("group.xls")) x_results = x.to_dict() survey_object = create_survey_element_from_dict(x_results) self.assertEqual(x_results, survey_object.to_dict())