44import pyexcel as pe
55import pyexcel_webio as webio
66from db import Session , Base , Signature , Signature2 , engine
7- from nose .tools import raises
7+ from nose .tools import raises , eq_
88if sys .version_info [0 ] == 2 and sys .version_info [1 ] < 7 :
99 from ordereddict import OrderedDict
1010else :
@@ -238,22 +238,28 @@ def setUp(self):
238238 [1 , 2 , 3 ],
239239 [4 , 5 , 6 ]
240240 ]
241+ self .test_sheet_name = 'custom sheet name'
241242
242243 def test_make_response_from_sheet (self ):
243244 sheet = pe .Sheet (self .data )
244- webio .make_response (sheet , "xls" , file_name = FILE_NAME )
245+ webio .make_response (sheet , "xls" , file_name = FILE_NAME ,
246+ sheet_name = self .test_sheet_name )
245247 self .verify ()
246248
247249 def test_make_response_from_array (self ):
248- webio .make_response_from_array (self .data , "xls" , file_name = FILE_NAME )
250+ webio .make_response_from_array (
251+ self .data , "xls" ,
252+ file_name = FILE_NAME , sheet_name = self .test_sheet_name )
249253 self .verify ()
250254
251255 def test_make_response_from_records (self ):
252256 records = [
253257 {"X" : 1 , "Y" : 2 , "Z" : 3 },
254258 {"X" : 4 , "Y" : 5 , "Z" : 6 }
255259 ]
256- webio .make_response_from_records (records , "xls" , file_name = FILE_NAME )
260+ webio .make_response_from_records (
261+ records , "xls" ,
262+ file_name = FILE_NAME , sheet_name = self .test_sheet_name )
257263 self .verify ()
258264
259265 def test_make_response_from_dict (self ):
@@ -262,7 +268,8 @@ def test_make_response_from_dict(self):
262268 "Y" : [2 , 5 ],
263269 "Z" : [3 , 6 ]
264270 }
265- webio .make_response_from_dict (adict , "xls" , file_name = FILE_NAME )
271+ webio .make_response_from_dict (
272+ adict , "xls" , file_name = FILE_NAME , sheet_name = self .test_sheet_name )
266273 self .verify ()
267274
268275 def test_make_response_from_table (self ):
@@ -274,8 +281,9 @@ def test_make_response_from_table(self):
274281 session .add (row1 )
275282 session .add (row2 )
276283 session .commit ()
277- webio .make_response_from_a_table (session , Signature , "xls" ,
278- file_name = FILE_NAME )
284+ webio .make_response_from_a_table (
285+ session , Signature , "xls" ,
286+ file_name = FILE_NAME , sheet_name = self .test_sheet_name )
279287 self .verify ()
280288 session .close ()
281289
@@ -290,8 +298,9 @@ def test_make_response_from_query_sets(self):
290298 session .commit ()
291299 query_sets = session .query (Signature ).filter_by (X = 1 ).all ()
292300 column_names = ["X" , "Y" , "Z" ]
293- webio .make_response_from_query_sets (query_sets , column_names , "xls" ,
294- file_name = FILE_NAME )
301+ webio .make_response_from_query_sets (
302+ query_sets , column_names , "xls" ,
303+ file_name = FILE_NAME , sheet_name = self .test_sheet_name )
295304 sheet2 = pe .get_sheet (file_name = OUTPUT )
296305 assert sheet2 .to_array () == [
297306 ["X" , "Y" , "Z" ],
@@ -302,6 +311,7 @@ def test_make_response_from_query_sets(self):
302311 def verify (self ):
303312 sheet2 = pe .get_sheet (file_name = OUTPUT )
304313 assert sheet2 .to_array () == self .data
314+ eq_ (sheet2 .name , self .test_sheet_name )
305315
306316 def tearDown (self ):
307317 if os .path .exists (OUTPUT ):
0 commit comments