Skip to content

Commit f583ab4

Browse files
committed
unit test #5
1 parent a5c91c7 commit f583ab4

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

django_excel/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def new_file(self, file_name, *args, **kwargs):
116116
self.content_type_extra)
117117

118118

119-
def make_response(content, content_type, status, file_name=None):
119+
def _make_response(content, content_type, status, file_name=None):
120120
"""
121121
Custom response function that is called by pyexcel-webio
122122
"""
@@ -126,7 +126,7 @@ def make_response(content, content_type, status, file_name=None):
126126
return response
127127

128128

129-
webio.ExcelResponse = make_response
129+
webio.ExcelResponse = _make_response
130130

131131

132132
from pyexcel_webio import (

polls/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
'',
77
url(r'^$', views.upload, name='uplink'),
88
url(r'^download/(.*)', views.download, name="download"),
9+
url(r'^download_attachment/(.*)/(.*)', views.download_as_attachment,
10+
name="download_attachment"),
911
url(r'^exchange/(.*)', views.exchange, name="exchange"),
1012
url(r'^parse/(.*)', views.parse, name="parse"),
1113
url(r'^import/', views.import_data, name="import"),

polls/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def download(request, file_type):
4242
sheet = excel.pe.Sheet(data)
4343
return excel.make_response(sheet, file_type)
4444

45+
46+
def download_as_attachment(request, file_type, file_name):
47+
return excel.make_response_from_array(data, file_type, file_name=file_name)
48+
4549

4650
def export_data(request, atype):
4751
if atype == "sheet":

testResponse.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ def test_download(self):
5959
array = sheet.to_array()
6060
assert array == self.data
6161

62+
def test_download_attachment(self):
63+
test_file_name = "test"
64+
for file_type in FILE_TYPE_MIME_TABLE.keys():
65+
print(file_type)
66+
response = self.client.get("/polls/download_attachment/"+file_type+"/"+test_file_name)
67+
assert response['Content-Type'] == FILE_TYPE_MIME_TABLE[file_type]
68+
assert response['Content-Disposition'] == "attachment; filename=%s.%s" % (test_file_name, file_type)
69+
sheet = pe.get_sheet(file_type=file_type, file_content=response.content)
70+
sheet.format(int)
71+
array = sheet.to_array()
72+
assert array == self.data
73+
6274
def test_parse_single_sheet(self):
6375
test_sample = {
6476
"array": {u'result': [[u'X', u'Y', u'Z'], [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]},

0 commit comments

Comments
 (0)