Skip to content

Commit 1344d31

Browse files
committed
test #15: throw exception if not dot found in the file name
1 parent 0d7449d commit 1344d31

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

tests/test_upload_n_download_excel.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,29 @@ def test_download(self):
5050
file_content=response.data)
5151
sheet.format(int)
5252
array = sheet.to_array()
53-
assert array == self.data
53+
eq_(array, self.data)
54+
55+
def test_no_file_type(self):
56+
file_name = 'issue15'
57+
download_file_type = "xls"
58+
io = pe.save_as(dest_file_type="xls",
59+
array=self.data)
60+
if not PY2:
61+
if not isinstance(io, BytesIO):
62+
io = BytesIO(io.getvalue().encode('utf-8'))
63+
response = self.app.post(
64+
'/switch/%s' % download_file_type,
65+
buffered=True,
66+
data={"file": (io, file_name)},
67+
content_type="multipart/form-data")
68+
eq_(response.content_type, 'text/html')
69+
eq_(response.status_code, 400)
5470

5571
def test_override_file_name(self):
5672
for file_type in FILE_TYPE_MIME_TABLE.keys():
5773
file_name = 'override_file_name'
5874
response = self.app.post('/file_name/%s/%s' % (file_type,
5975
file_name))
60-
assert response.content_type == FILE_TYPE_MIME_TABLE[file_type]
61-
assert response.headers.get("Content-Disposition", None) == (
62-
"attachment; filename=%s.%s" % (file_name, file_type))
76+
eq_(response.content_type, FILE_TYPE_MIME_TABLE[file_type])
77+
eq_(response.headers.get("Content-Disposition", None),
78+
("attachment; filename=%s.%s" % (file_name, file_type)))

tests/testapp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask, request, jsonify
1+
from flask import Flask, request, jsonify, abort
22
from flask.ext import excel
33
import pyexcel as pe
44
from flask.ext.sqlalchemy import SQLAlchemy
@@ -75,8 +75,11 @@ def respond_array(struct_type):
7575

7676
@app.route("/switch/<file_type>", methods=['POST'])
7777
def switch(file_type):
78-
sheet = request.get_sheet(field_name='file')
79-
return excel.make_response(sheet, file_type)
78+
try:
79+
sheet = request.get_sheet(field_name='file')
80+
return excel.make_response(sheet, file_type)
81+
except IOError:
82+
abort(400)
8083

8184

8285
@app.route("/file_name/<file_type>/<file_name>", methods=['POST'])

0 commit comments

Comments
 (0)