Skip to content

Commit 8616c72

Browse files
committed
fix #38, test unicode in download file name
1 parent 865cfe0 commit 8616c72

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

testResponse.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
import os
24
import sys
35
import json
@@ -64,13 +66,24 @@ def test_download(self):
6466
array = sheet.to_array()
6567
assert array == self.data
6668

67-
def test_download_attachment(self):
69+
def test_download_attachment_with_ascii_name(self):
6870
test_file_name = "test"
71+
self._download_and_verify_file_name(test_file_name)
72+
73+
def test_download_attachment_with_unicode_name(self):
74+
test_file_name = u'中文文件名'
75+
self._download_and_verify_file_name(test_file_name.encode('utf-8'))
76+
77+
def test_download_attachment_with_unicode_name_as_string(self):
78+
test_file_name = '中文文件名'
79+
self._download_and_verify_file_name(test_file_name)
80+
81+
def _download_and_verify_file_name(self, file_name):
6982
for file_type in FILE_TYPE_MIME_TABLE.keys():
7083
print(file_type)
84+
url_encoded_file_name = urllib_quote(file_name)
7185
response = self.client.get(
72-
"/polls/download_attachment/"+file_type+"/"+test_file_name)
73-
url_encoded_file_name = urllib_quote(test_file_name)
86+
"/polls/download_attachment/"+file_type+"/"+file_name)
7487
assert response['Content-Type'] == FILE_TYPE_MIME_TABLE[file_type]
7588
assert response['Content-Disposition'] == (
7689
"attachment; filename=%s.%s;filename*=utf-8''%s.%s"

0 commit comments

Comments
 (0)