def test_build_sections_from_survey(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.set_survey(survey) # test that we generate the proper sections expected_sections = [ survey.name, 'children', 'children/cartoons', 'children/cartoons/characters' ] self.assertEqual(expected_sections, [s['name'] for s in export_builder.sections]) # main section should have split geolocations expected_element_names = [ 'name', 'age', 'geo/geolocation', 'geo/_geolocation_longitude', 'geo/_geolocation_latitude', 'geo/_geolocation_altitude', 'geo/_geolocation_precision', 'tel/tel.office', 'tel/tel.mobile', 'meta/instanceID' ] section = export_builder.section_by_name(survey.name) element_names = [element['xpath'] for element in section['elements']] # fav_colors should have its choices split self.assertEqual(sorted(expected_element_names), sorted(element_names)) expected_element_names = [ 'children/name', 'children/age', 'children/fav_colors', 'children/fav_colors/red', 'children/fav_colors/blue', 'children/fav_colors/pink', 'children/ice.creams', 'children/ice.creams/vanilla', 'children/ice.creams/strawberry', 'children/ice.creams/chocolate' ] section = export_builder.section_by_name('children') element_names = [element['xpath'] for element in section['elements']] self.assertEqual(sorted(expected_element_names), sorted(element_names)) expected_element_names = [ 'children/cartoons/name', 'children/cartoons/why' ] section = export_builder.section_by_name('children/cartoons') element_names = [element['xpath'] for element in section['elements']] self.assertEqual(sorted(expected_element_names), sorted(element_names)) expected_element_names = [ 'children/cartoons/characters/name', 'children/cartoons/characters/good_or_evil' ] section = \ export_builder.section_by_name('children/cartoons/characters') element_names = [element['xpath'] for element in section['elements']] self.assertEqual(sorted(expected_element_names), sorted(element_names))
def test_build_sections_from_survey(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.set_survey(survey) # test that we generate the proper sections expected_sections = [ survey.name, 'children', 'children/cartoons', 'children/cartoons/characters'] self.assertEqual( expected_sections, [s['name'] for s in export_builder.sections]) # main section should have split geolocations expected_element_names = [ 'name', 'age', 'geo/geolocation', 'geo/_geolocation_longitude', 'geo/_geolocation_latitude', 'geo/_geolocation_altitude', 'geo/_geolocation_precision', 'tel/tel.office', 'tel/tel.mobile', 'meta/instanceID'] section = export_builder.section_by_name(survey.name) element_names = [element['xpath'] for element in section['elements']] # fav_colors should have its choices split self.assertEqual( sorted(expected_element_names), sorted(element_names)) expected_element_names = [ 'children/name', 'children/age', 'children/fav_colors', 'children/fav_colors/red', 'children/fav_colors/blue', 'children/fav_colors/pink', 'children/ice.creams', 'children/ice.creams/vanilla', 'children/ice.creams/strawberry', 'children/ice.creams/chocolate'] section = export_builder.section_by_name('children') element_names = [element['xpath'] for element in section['elements']] self.assertEqual( sorted(expected_element_names), sorted(element_names)) expected_element_names = [ 'children/cartoons/name', 'children/cartoons/why'] section = export_builder.section_by_name('children/cartoons') element_names = [element['xpath'] for element in section['elements']] self.assertEqual( sorted(expected_element_names), sorted(element_names)) expected_element_names = [ 'children/cartoons/characters/name', 'children/cartoons/characters/good_or_evil'] section = \ export_builder.section_by_name('children/cartoons/characters') element_names = [element['xpath'] for element in section['elements']] self.assertEqual( sorted(expected_element_names), sorted(element_names))
def test_delimiter_replacement_works_existing_fields(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = "." export_builder.set_survey(survey) expected_sections =\ [ { 'name': 'children', 'elements': [ { 'title': 'children.name', 'xpath': 'children/name' } ] } ] children_section = export_builder.section_by_name('children') self.assertEqual(children_section['elements'][0]['title'], expected_sections[0]['elements'][0]['title'])
def test_delimiter_replacement_works_generated_multi_select_fields(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = "." export_builder.set_survey(survey) expected_section =\ { 'name': 'children', 'elements': [ { 'title': 'children.fav_colors.red', 'xpath': 'children/fav_colors/red' } ] } childrens_section = export_builder.section_by_name('children') match = filter(lambda x: expected_section['elements'][0]['xpath'] == x['xpath'], childrens_section['elements'])[0] self.assertEqual( expected_section['elements'][0]['title'], match['title'])
def test_delimiter_replacement_works_for_generated_gps_fields(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = "." export_builder.set_survey(survey) expected_section = \ { 'name': 'childrens_survey', 'elements': [ { 'title': 'geo._geolocation_latitude', 'xpath': 'geo/_geolocation_latitude' } ] } main_section = export_builder.section_by_name('childrens_survey') match = filter( lambda x: (expected_section['elements'][0]['xpath'] == x['xpath']), main_section['elements'])[0] self.assertEqual(expected_section['elements'][0]['title'], match['title'])
def test_delimiter_replacement_works_generated_multi_select_fields(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = "." export_builder.set_survey(survey) expected_section =\ { 'name': 'children', 'elements': [ { 'title': 'children.fav_colors.red', 'xpath': 'children/fav_colors/red' } ] } childrens_section = export_builder.section_by_name('children') match = filter( lambda x: expected_section['elements'][0]['xpath'] == x['xpath'], childrens_section['elements'])[0] self.assertEqual(expected_section['elements'][0]['title'], match['title'])
def test_delimiter_replacement_works_for_generated_gps_fields(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = "." export_builder.set_survey(survey) expected_section = \ { 'name': 'childrens_survey', 'elements': [ { 'title': 'geo._geolocation_latitude', 'xpath': 'geo/_geolocation_latitude' } ] } main_section = export_builder.section_by_name('childrens_survey') match = filter( lambda x: (expected_section['elements'][0]['xpath'] == x['xpath']), main_section['elements'])[0] self.assertEqual( expected_section['elements'][0]['title'], match['title'])
def test_delimiter_replacement_works_existing_fields(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = "." export_builder.set_survey(survey) expected_sections =\ [ { 'name': 'children', 'elements': [ { 'title': 'children.name', 'xpath': 'children/name' } ] } ] children_section = export_builder.section_by_name('children') self.assertEqual( children_section['elements'][0]['title'], expected_sections[0]['elements'][0]['title'])