在我的一个应用程序测试用例中,我必须打开电子邮件附件文件并验证数据是否为excel文件。我在测试中收到的电子邮件附件就是这样的
\ xd0 \ xcf \ x11 \ xe0 \ xa1 \ xb1 \ x1a \ xe1 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00> \ x00 \ x03 \ x00 \ xfe \ xff \ t \ x00 \ x06 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ t \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x10 \ x00 \ x00 \ xfe \ xff \ xff \ xff \ x00 \ x00 \ x00 \ x00 \ x00 \ xfe \ xff \ xff \ xff \ x00 \ x00 \ x00 \ x00 \ x08 \ x00 \ x00 \ x00 \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ x
如何将其转换回Excel文件。
这是我的测试代码
def test_for_attachments(self):
self.response = self.client.post(reverse('batches:detail_excel', kwargs={'batch_id': self.batch.id}))
attachments = mail.outbox[0].attachments
self.assertEqual(attachments[0][0],'success-report.xls')
self.assertEqual(attachments[0][2],'application/vnd.ms-excel')
self.assertContains(attachments[0][1],self.user.username)
attachments [0] [1]是内容文件。