|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +try: |
| 4 | + from urllib import quote |
| 5 | +except ImportError: |
| 6 | + from urllib.parse import quote |
| 7 | + |
1 | 8 | from testapp import app
|
2 | 9 | import pyexcel as pe
|
3 | 10 | from nose.tools import eq_
|
@@ -71,8 +78,35 @@ def test_no_file_type(self):
|
71 | 78 | def test_override_file_name(self):
|
72 | 79 | for file_type in FILE_TYPE_MIME_TABLE.keys():
|
73 | 80 | file_name = 'override_file_name'
|
| 81 | + url_encoded_file_name = quote(file_name) |
| 82 | + response = self.app.post('/file_name/%s/%s' % (file_type, |
| 83 | + file_name)) |
| 84 | + eq_(response.content_type, FILE_TYPE_MIME_TABLE[file_type]) |
| 85 | + eq_(response.headers.get("Content-Disposition", None), |
| 86 | + ("attachment; filename=%s.%s;filename*=utf-8''%s.%s" |
| 87 | + % (url_encoded_file_name, file_type, |
| 88 | + url_encoded_file_name, file_type))) |
| 89 | + |
| 90 | + def test_unicode_file_name(self): |
| 91 | + for file_type in FILE_TYPE_MIME_TABLE.keys(): |
| 92 | + file_name = u'中文文件名' |
| 93 | + url_encoded_file_name = quote(file_name.encode('utf-8')) |
| 94 | + response = self.app.post('/file_name/%s/%s' % (file_type, |
| 95 | + file_name)) |
| 96 | + eq_(response.content_type, FILE_TYPE_MIME_TABLE[file_type]) |
| 97 | + eq_(response.headers.get("Content-Disposition", None), |
| 98 | + ("attachment; filename=%s.%s;filename*=utf-8''%s.%s" |
| 99 | + % (url_encoded_file_name, file_type, |
| 100 | + url_encoded_file_name, file_type))) |
| 101 | + |
| 102 | + def test_utf8_file_name(self): |
| 103 | + for file_type in FILE_TYPE_MIME_TABLE.keys(): |
| 104 | + file_name = '中文文件名' |
| 105 | + url_encoded_file_name = quote(file_name) |
74 | 106 | response = self.app.post('/file_name/%s/%s' % (file_type,
|
75 | 107 | file_name))
|
76 | 108 | eq_(response.content_type, FILE_TYPE_MIME_TABLE[file_type])
|
77 | 109 | eq_(response.headers.get("Content-Disposition", None),
|
78 |
| - ("attachment; filename=%s.%s" % (file_name, file_type))) |
| 110 | + ("attachment; filename=%s.%s;filename*=utf-8''%s.%s" |
| 111 | + % (url_encoded_file_name, file_type, |
| 112 | + url_encoded_file_name, file_type))) |
0 commit comments