Example #1
0
    def test_should_export_data_in_xlsx(self):
        local_time_delta = '+', 0, 0
        submission_formatter = SubmissionFormatter(self.columns,
                                                   local_time_delta,
                                                   self.preferences)
        header_list = submission_formatter.format_header_data()
        file_response = export_to_new_excel(header_list, self.data, 'filename',
                                            submission_formatter)
        self.assertTrue(isinstance(file_response, HttpResponse))
        self.assertEquals(file_response.get('Content-Disposition', None),
                          "attachment; filename=filename.xlsx")

        f = StringIO.StringIO(file_response.content)
        wb = load_workbook(f)
        ws = wb.get_active_sheet()
        row_values = [[cell.value for cell in row] for row in ws.rows]
        expected_row_values = [[
            u'Submission Date', u'Data Sender Name', u'Data Sender Id',
            u"What is the city's last name?",
            u"What is the city's Unique ID Number?", u'Total sales'
        ],
                               [
                                   datetime.datetime(2016, 1, 30, 19, 32, 59,
                                                     999997), u'Einstein',
                                   u'rep2', u'chennai', u'cit1', 5000
                               ]]

        column_values = [[cell.value for cell in column]
                         for column in ws.columns]
        expected_column_values = [[
            u'Submission Date',
            datetime.datetime(2016, 1, 30, 19, 32, 59, 999997)
        ], [u'Data Sender Name', u'Einstein'
            ], [u'Data Sender Id', u'rep2'
                ], [u"What is the city's last name?", u'chennai'
                    ], [u"What is the city's Unique ID Number?", u'cit1'],
                                  [u'Total sales', 5000]]
        self.assertEqual(len(ws.rows), 2)
        self.assertEqual(len(ws.columns), 6)
        self.assertEqual(row_values, expected_row_values)
        self.assertEqual(column_values, expected_column_values)
        f.close()
Example #2
0
 def _get_header_list(self, columns):
     submission_formatter = SubmissionFormatter(columns,
                                                self.local_time_delta,
                                                self.preferences)
     header_list = submission_formatter.format_header_data()
     return header_list, submission_formatter