def test_download(self): for upload_file_type in FILE_TYPE_MIME_TABLE.keys(): file_name = 'test.%s' % upload_file_type for download_file_type in FILE_TYPE_MIME_TABLE.keys(): print("Uploading %s Downloading %s" % (upload_file_type, download_file_type)) io = pe.get_io(upload_file_type) sheet = pe.Sheet(self.data) sheet.save_to_memory(upload_file_type, io) io.seek(0) if not PY2: if not isinstance(io, BytesIO): io = BytesIO(io.getvalue().encode('utf-8')) response = self.app.post('/switch/%s' % download_file_type, buffered=True, data={"file": (io, file_name)}, content_type="multipart/form-data") assert response.content_type == FILE_TYPE_MIME_TABLE[download_file_type] sheet = pe.load_from_memory(download_file_type, response.data) sheet.format(int) array = sheet.to_array() assert array == self.data
def make_response(pyexcel_instance, file_type, status=200, **keywords): """Make a http response from a pyexcel instance of :class:`~pyexcel.Sheet` or :class:`~pyexcel.Book` :param pyexcel_instance: pyexcel.Sheet or pyexcel.Book :param file_type: one of the following strings: * 'csv' * 'tsv' * 'csvz' * 'tsvz' * 'xls' * 'xlsx' * 'xlsm' * 'ods' :param status: unless a different status is to be returned. """ io = pe.get_io(file_type) pyexcel_instance.save_to_memory(file_type, io, **keywords) io.seek(0) return ExcelResponse(io.read(), content_type=FILE_TYPE_MIME_TABLE[file_type], status=status)
def make_response(pyexcel_instance, file_type, status=200, file_name=None, **keywords): """ Make a http response from a pyexcel instance of :class:`~pyexcel.Sheet` or :class:`~pyexcel.Book` :param pyexcel_instance: pyexcel.Sheet or pyexcel.Book :param file_type: one of the following strings: * 'csv' * 'tsv' * 'csvz' * 'tsvz' * 'xls' * 'xlsx' * 'xlsm' * 'ods' :param status: unless a different status is to be returned. :returns: http response """ io = pe.get_io(file_type) pyexcel_instance.save_to_memory(file_type, io, **keywords) return _make_response(io, file_type, status, file_name)
def test_upload_and_download(self): for upload_file_type in FILE_TYPE_MIME_TABLE.keys(): file_name = 'test.%s' % upload_file_type for download_file_type in FILE_TYPE_MIME_TABLE.keys(): print("Uploading %s Downloading %s" % (upload_file_type, download_file_type)) io = pe.get_io(upload_file_type) sheet = pe.Sheet(self.data) sheet.save_to_memory(upload_file_type, io) io.seek(0) if not PY2: if isinstance(io, BytesIO): content = io.getvalue() else: content = io.getvalue().encode('utf-8') else: content = io.getvalue() response = self.app.post('/switch/%s' % download_file_type, upload_files = [('file', file_name, content)], ) assert response.content_type == FILE_TYPE_MIME_TABLE[download_file_type] sheet = pe.get_sheet(file_type=download_file_type, file_content=response.body) sheet.format(int) array = sheet.to_array() assert array == self.data