def test_child_record_parent_table_is_updated_when_sheet_is_renamed(self): survey = create_survey_from_xls(_logger_fixture_path( 'childrens_survey_with_a_very_long_name.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xlsx') filename = xls_file.name export_builder.to_xls_export(filename, self.long_survey_data) xls_file.seek(0) wb = load_workbook(filename) # get the children's sheet ws1 = wb.get_sheet_by_name('childrens_survey_with_a_very_l1') # parent_table is in cell K2 parent_table_name = ws1.cell('K2').value expected_parent_table_name = 'childrens_survey_with_a_very_lo' self.assertEqual(parent_table_name, expected_parent_table_name) # get cartoons sheet ws2 = wb.get_sheet_by_name('childrens_survey_with_a_very_l2') parent_table_name = ws2.cell('G2').value expected_parent_table_name = 'childrens_survey_with_a_very_l1' self.assertEqual(parent_table_name, expected_parent_table_name) xls_file.close()
def test_child_record_parent_table_is_updated_when_sheet_is_renamed(self): survey = create_survey_from_xls( _logger_fixture_path('childrens_survey_with_a_very_long_name.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xlsx') filename = xls_file.name export_builder.to_xls_export(filename, self.long_survey_data) xls_file.seek(0) wb = load_workbook(filename) # get the children's sheet ws1 = wb.get_sheet_by_name('childrens_survey_with_a_very_l1') # parent_table is in cell K2 parent_table_name = ws1.cell('K2').value expected_parent_table_name = 'childrens_survey_with_a_very_lo' self.assertEqual(parent_table_name, expected_parent_table_name) # get cartoons sheet ws2 = wb.get_sheet_by_name('childrens_survey_with_a_very_l2') parent_table_name = ws2.cell('G2').value expected_parent_table_name = 'childrens_survey_with_a_very_l1' self.assertEqual(parent_table_name, expected_parent_table_name) xls_file.close()
def test_to_xls_export_respects_custom_field_delimiter(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = ExportBuilder.GROUP_DELIMITER_DOT export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xls') filename = xls_file.name export_builder.to_xls_export(filename, self.data) xls_file.seek(0) wb = load_workbook(filename) # check header columns main_sheet = wb.get_sheet_by_name('childrens_survey') expected_column_headers = [ u'name', u'age', u'geo.geolocation', u'geo._geolocation_latitude', u'geo._geolocation_longitude', u'geo._geolocation_altitude', u'geo._geolocation_precision', u'tel.tel.office', u'tel.tel.mobile', u'_id', u'meta.instanceID', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version' ] column_headers = [c[0].value for c in main_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) xls_file.close()
def test_xls_convert_dates_before_1900(self): survey = create_survey_from_xls( viewer_fixture_path('test_data_types/test_data_types.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) data = [{ 'name': 'Abe', 'when': '1899-07-03', }] # create export file temp_xls_file = NamedTemporaryFile(suffix='.xlsx') export_builder.to_xls_export(temp_xls_file.name, data) temp_xls_file.close()
def test_xls_convert_dates_before_1900(self): survey = create_survey_from_xls(viewer_fixture_path( 'test_data_types/test_data_types.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) data = [ { 'name': 'Abe', 'when': '1899-07-03', } ] # create export file temp_xls_file = NamedTemporaryFile(suffix='.xlsx') export_builder.to_xls_export(temp_xls_file.name, data) temp_xls_file.close()
def test_xls_export_works_with_unicode(self): survey = create_survey_from_xls( _logger_fixture_path('childrens_survey_unicode.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) temp_xls_file = NamedTemporaryFile(suffix='.xlsx') export_builder.to_xls_export(temp_xls_file.name, self.data_utf8) temp_xls_file.seek(0) # check that values for red\u2019s and blue\u2019s are set to true wb = load_workbook(temp_xls_file.name) children_sheet = wb.get_sheet_by_name("children.info") data = dict([(r[0].value, r[1].value) for r in children_sheet.columns]) self.assertTrue(data[u'children.info/fav_colors/red\u2019s']) self.assertTrue(data[u'children.info/fav_colors/blue\u2019s']) self.assertFalse(data[u'children.info/fav_colors/pink\u2019s']) temp_xls_file.close()
def test_xls_export_works_with_unicode(self): survey = create_survey_from_xls(_logger_fixture_path( 'childrens_survey_unicode.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) temp_xls_file = NamedTemporaryFile(suffix='.xlsx') export_builder.to_xls_export(temp_xls_file.name, self.data_utf8) temp_xls_file.seek(0) # check that values for red\u2019s and blue\u2019s are set to true wb = load_workbook(temp_xls_file.name) children_sheet = wb.get_sheet_by_name("children.info") data = dict([(r[0].value, r[1].value) for r in children_sheet.columns]) self.assertTrue(data[u'children.info/fav_colors/red\u2019s']) self.assertTrue(data[u'children.info/fav_colors/blue\u2019s']) self.assertFalse(data[u'children.info/fav_colors/pink\u2019s']) temp_xls_file.close()
def test_to_xls_export_generates_valid_sheet_names(self): survey = create_survey_from_xls(_logger_fixture_path( 'childrens_survey_with_a_very_long_name.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xls') filename = xls_file.name export_builder.to_xls_export(filename, self.data) xls_file.seek(0) wb = load_workbook(filename) # check that we have childrens_survey, children, children_cartoons # and children_cartoons_characters sheets expected_sheet_names = ['childrens_survey_with_a_very_lo', 'childrens_survey_with_a_very_l1', 'childrens_survey_with_a_very_l2', 'childrens_survey_with_a_very_l3'] self.assertEqual(wb.get_sheet_names(), expected_sheet_names) xls_file.close()
def test_to_xls_export_generates_valid_sheet_names(self): survey = create_survey_from_xls( _logger_fixture_path('childrens_survey_with_a_very_long_name.xls')) export_builder = ExportBuilder() export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xls') filename = xls_file.name export_builder.to_xls_export(filename, self.data) xls_file.seek(0) wb = load_workbook(filename) # check that we have childrens_survey, children, children_cartoons # and children_cartoons_characters sheets expected_sheet_names = [ 'childrens_survey_with_a_very_lo', 'childrens_survey_with_a_very_l1', 'childrens_survey_with_a_very_l2', 'childrens_survey_with_a_very_l3' ] self.assertEqual(wb.get_sheet_names(), expected_sheet_names) xls_file.close()
def test_to_xls_export_respects_custom_field_delimiter(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.GROUP_DELIMITER = ExportBuilder.GROUP_DELIMITER_DOT export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xls') filename = xls_file.name export_builder.to_xls_export(filename, self.data) xls_file.seek(0) wb = load_workbook(filename) # check header columns main_sheet = wb.get_sheet_by_name('childrens_survey') expected_column_headers = [ u'name', u'age', u'geo.geolocation', u'geo._geolocation_latitude', u'geo._geolocation_longitude', u'geo._geolocation_altitude', u'geo._geolocation_precision', u'tel.tel.office', u'tel.tel.mobile', u'_id', u'meta.instanceID', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version'] column_headers = [c[0].value for c in main_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) xls_file.close()
def test_to_xls_export_works(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xls') filename = xls_file.name export_builder.to_xls_export(filename, self.data) xls_file.seek(0) wb = load_workbook(filename) # check that we have childrens_survey, children, children_cartoons # and children_cartoons_characters sheets expected_sheet_names = [ 'childrens_survey', 'children', 'children_cartoons', 'children_cartoons_characters' ] self.assertEqual(wb.get_sheet_names(), expected_sheet_names) # check header columns main_sheet = wb.get_sheet_by_name('childrens_survey') expected_column_headers = [ u'name', u'age', u'geo/geolocation', u'geo/_geolocation_latitude', u'geo/_geolocation_longitude', u'geo/_geolocation_altitude', u'geo/_geolocation_precision', u'tel/tel.office', u'tel/tel.mobile', u'_id', u'meta/instanceID', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version' ] column_headers = [c[0].value for c in main_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) childrens_sheet = wb.get_sheet_by_name('children') expected_column_headers = [ u'children/name', u'children/age', u'children/fav_colors', u'children/fav_colors/red', u'children/fav_colors/blue', u'children/fav_colors/pink', u'children/ice.creams', u'children/ice.creams/vanilla', u'children/ice.creams/strawberry', u'children/ice.creams/chocolate', u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version' ] column_headers = [c[0].value for c in childrens_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) cartoons_sheet = wb.get_sheet_by_name('children_cartoons') expected_column_headers = [ u'children/cartoons/name', u'children/cartoons/why', u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version' ] column_headers = [c[0].value for c in cartoons_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) characters_sheet = wb.get_sheet_by_name('children_cartoons_characters') expected_column_headers = [ u'children/cartoons/characters/name', u'children/cartoons/characters/good_or_evil', u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version' ] column_headers = [c[0].value for c in characters_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) xls_file.close()
def test_to_xls_export_works(self): survey = self._create_childrens_survey() export_builder = ExportBuilder() export_builder.set_survey(survey) xls_file = NamedTemporaryFile(suffix='.xls') filename = xls_file.name export_builder.to_xls_export(filename, self.data) xls_file.seek(0) wb = load_workbook(filename) # check that we have childrens_survey, children, children_cartoons # and children_cartoons_characters sheets expected_sheet_names = ['childrens_survey', 'children', 'children_cartoons', 'children_cartoons_characters'] self.assertEqual(wb.get_sheet_names(), expected_sheet_names) # check header columns main_sheet = wb.get_sheet_by_name('childrens_survey') expected_column_headers = [ u'name', u'age', u'geo/geolocation', u'geo/_geolocation_latitude', u'geo/_geolocation_longitude', u'geo/_geolocation_altitude', u'geo/_geolocation_precision', u'tel/tel.office', u'tel/tel.mobile', u'_id', u'meta/instanceID', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version'] column_headers = [c[0].value for c in main_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) childrens_sheet = wb.get_sheet_by_name('children') expected_column_headers = [ u'children/name', u'children/age', u'children/fav_colors', u'children/fav_colors/red', u'children/fav_colors/blue', u'children/fav_colors/pink', u'children/ice.creams', u'children/ice.creams/vanilla', u'children/ice.creams/strawberry', u'children/ice.creams/chocolate', u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version'] column_headers = [c[0].value for c in childrens_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) cartoons_sheet = wb.get_sheet_by_name('children_cartoons') expected_column_headers = [ u'children/cartoons/name', u'children/cartoons/why', u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version'] column_headers = [c[0].value for c in cartoons_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) characters_sheet = wb.get_sheet_by_name('children_cartoons_characters') expected_column_headers = [ u'children/cartoons/characters/name', u'children/cartoons/characters/good_or_evil', u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_index', u'_parent_table_name', u'_tags', '_notes', '_version'] column_headers = [c[0].value for c in characters_sheet.columns] self.assertEqual(sorted(column_headers), sorted(expected_column_headers)) xls_file.close()