def test_xls_in_zip_file(self, browser): ticket_builder = Builder('ticket') ticket_builder.titled(u'T\xc3st') ticket_builder.with_id('1') ticket_builder.having(dueDate=DateTime(2011, 11, 10, 17, 14, 35), ticket_description='<p>This is a<br />test.</p>') ticket_builder.within(self.ticketbox) with freeze(datetime(2011, 2, 3, 5, 7, 11)): create(ticket_builder) browser.login() browser.visit(self.ticketbox, view='zip_export') self.assertEquals('application/zip', browser.headers['Content-Type']) zipfile = ZipFile(StringIO(browser.contents)) self.assertEquals(['ticketbox.xlsx'], zipfile.namelist()) xlsx = zipfile.read('ticketbox.xlsx') workbook = open_workbook(file_contents=xlsx) sheet = workbook.sheet_by_index(0) data = map(sheet.row_values, range(sheet.nrows)) headers = data.pop(0) data = map( lambda row: dict(zip(headers, row)), data ) self.maxDiff = None self.assertEquals( first=[ { u'Created': u'03.02.2011 05:07', u'Due date': u'10.11.2011 17:14', u'No.': u'1', u'Description': u' This is a test. ', u'Releases': u'', u'Creator': u'test_user_1_', u'Responsible': u'', u'Watched release': u'', u'Priorities': u'', u'State': u'', u'Variety': u'', u'Title': u'T\xc3st', u'Area': u'', } ], second=data )
def test_xlsx_export(self): ticketbox = create(Builder('ticket box') .titled(u'My Tickät Box')) ticket_builder = Builder('ticket') ticket_builder.titled(u'Täst') ticket_builder.with_id('1') ticket_builder.having(dueDate=DateTime(2010, 11, 10, 17, 14, 35), ticket_description="<p>This is a<br />test.</p>") ticket_builder.within(ticketbox) with freeze(datetime(2010, 11, 1, 8, 25, 20)): create(ticket_builder) export_view = ticketbox.restrictedTraverse('tickets_export_xlsx') response = export_view() workbook = open_workbook(file_contents=response) sheet = workbook.sheet_by_index(0) data = map(sheet.row_values, range(sheet.nrows)) headers = data.pop(0) data = map( lambda row: dict(zip(headers, row)), data ) self.maxDiff = None self.assertEquals( first=[ { u'Created': u'01.11.2010 08:25', u'Due date': u'10.11.2010 17:14', u'No.': u'1', u'Description': u' This is a test. ', u'Releases': u'', u'Creator': u'test_user_1_', u'Responsible': u'', u'Watched release': u'', u'Priorities': u'', u'State': u'', u'Variety': u'', u'Title': u'Täst', u'Area': u'', } ], second=data )