@@ -76,37 +76,29 @@ def test_no_file_type(self):
7676 eq_ (response .status_code , 400 )
7777
7878 def test_override_file_name (self ):
79- for file_type in FILE_TYPE_MIME_TABLE .keys ():
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 )))
79+ file_name = 'override_file_name'
80+ url_encoded_file_name = quote (file_name )
81+ self ._download_and_verify_file_name (
82+ file_name , url_encoded_file_name )
8983
9084 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 )))
85+ file_name = u'中文文件名'
86+ url_encoded_file_name = quote (file_name .encode ('utf-8' ))
87+ self ._download_and_verify_file_name (
88+ file_name , url_encoded_file_name )
10189
10290 def test_utf8_file_name (self ):
91+ file_name = '中文文件名'
92+ url_encoded_file_name = quote (file_name )
93+ self ._download_and_verify_file_name (
94+ file_name , url_encoded_file_name )
95+
96+ def _download_and_verify_file_name (self , file_name , expected_file_name ):
10397 for file_type in FILE_TYPE_MIME_TABLE .keys ():
104- file_name = '中文文件名'
105- url_encoded_file_name = quote (file_name )
10698 response = self .app .post ('/file_name/%s/%s' % (file_type ,
10799 file_name ))
108100 eq_ (response .content_type , FILE_TYPE_MIME_TABLE [file_type ])
109101 eq_ (response .headers .get ("Content-Disposition" , None ),
110102 ("attachment; filename=%s.%s;filename*=utf-8''%s.%s"
111- % (url_encoded_file_name , file_type ,
112- url_encoded_file_name , file_type )))
103+ % (expected_file_name , file_type ,
104+ expected_file_name , file_type )))
0 commit comments