4
4
import pyexcel as pe
5
5
import pyexcel_webio as webio
6
6
from db import Session , Base , Signature , Signature2 , engine
7
- from nose .tools import raises
7
+ from nose .tools import raises , eq_
8
8
if sys .version_info [0 ] == 2 and sys .version_info [1 ] < 7 :
9
9
from ordereddict import OrderedDict
10
10
else :
@@ -238,22 +238,28 @@ def setUp(self):
238
238
[1 , 2 , 3 ],
239
239
[4 , 5 , 6 ]
240
240
]
241
+ self .test_sheet_name = 'custom sheet name'
241
242
242
243
def test_make_response_from_sheet (self ):
243
244
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 )
245
247
self .verify ()
246
248
247
249
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 )
249
253
self .verify ()
250
254
251
255
def test_make_response_from_records (self ):
252
256
records = [
253
257
{"X" : 1 , "Y" : 2 , "Z" : 3 },
254
258
{"X" : 4 , "Y" : 5 , "Z" : 6 }
255
259
]
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 )
257
263
self .verify ()
258
264
259
265
def test_make_response_from_dict (self ):
@@ -262,7 +268,8 @@ def test_make_response_from_dict(self):
262
268
"Y" : [2 , 5 ],
263
269
"Z" : [3 , 6 ]
264
270
}
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 )
266
273
self .verify ()
267
274
268
275
def test_make_response_from_table (self ):
@@ -274,8 +281,9 @@ def test_make_response_from_table(self):
274
281
session .add (row1 )
275
282
session .add (row2 )
276
283
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 )
279
287
self .verify ()
280
288
session .close ()
281
289
@@ -290,8 +298,9 @@ def test_make_response_from_query_sets(self):
290
298
session .commit ()
291
299
query_sets = session .query (Signature ).filter_by (X = 1 ).all ()
292
300
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 )
295
304
sheet2 = pe .get_sheet (file_name = OUTPUT )
296
305
assert sheet2 .to_array () == [
297
306
["X" , "Y" , "Z" ],
@@ -302,6 +311,7 @@ def test_make_response_from_query_sets(self):
302
311
def verify (self ):
303
312
sheet2 = pe .get_sheet (file_name = OUTPUT )
304
313
assert sheet2 .to_array () == self .data
314
+ eq_ (sheet2 .name , self .test_sheet_name )
305
315
306
316
def tearDown (self ):
307
317
if os .path .exists (OUTPUT ):
0 commit comments