@@ -25,6 +25,12 @@ def load_book(self, filename=None, **keywords):
25
25
return pe .get_book (file_name = filename , ** keywords )
26
26
27
27
28
+ class TestExtendedInput (webio .ExcelInputInMultiDict ):
29
+ """This is sample implementation that read excel source from file"""
30
+ def get_file_tuple (self , field_name ):
31
+ return field_name
32
+
33
+
28
34
def dumpy_response (content , content_type = None , status = 200 ):
29
35
"""A dummy response"""
30
36
f = open (OUTPUT , 'wb' )
@@ -46,6 +52,11 @@ def test_load_book(self):
46
52
testinput = webio .ExcelInput ()
47
53
testinput .get_book (filename = "test" ) # booom
48
54
55
+ @raises (NotImplementedError )
56
+ def test_excel_input_get_file_tuple (self ):
57
+ testinput = webio .ExcelInputInMultiDict ()
58
+ testinput .get_file_tuple (field_name = "test" ) # booom
59
+
49
60
def test_get_sheet (self ):
50
61
myinput = TestInput ()
51
62
sheet = myinput .get_sheet (unrelated = "foo bar" )
@@ -82,7 +93,6 @@ def test_dummy_function(self):
82
93
83
94
84
95
# excel inputs
85
-
86
96
class TestExcelInput :
87
97
def setUp (self ):
88
98
self .data = [
@@ -134,6 +144,27 @@ def test_save_to_database(self):
134
144
def tearDown (self ):
135
145
os .unlink (self .testfile )
136
146
147
+ class TestExcelInput2 :
148
+ def setUp (self ):
149
+ self .data = [
150
+ ["X" , "Y" , "Z" ],
151
+ [1 , 2 , 3 ],
152
+ [4 , 5 , 6 ]
153
+ ]
154
+ sheet = pe .Sheet (self .data )
155
+ self .testfile = "testfile.xls"
156
+ sheet .save_as (self .testfile )
157
+
158
+ def tearDown (self ):
159
+ os .unlink (self .testfile )
160
+
161
+ def test_get_sheet (self ):
162
+ myinput = TestExtendedInput ()
163
+ f = open (self .testfile , 'rb' )
164
+ sheet = myinput .get_sheet (field_name = ('xls' , f ))
165
+ assert sheet .to_array () == self .data
166
+ f .close ()
167
+
137
168
138
169
class TestExcelInputOnBook :
139
170
def setUp (self ):
@@ -173,8 +204,28 @@ def test_save_to_database(self):
173
204
def tearDown (self ):
174
205
os .unlink (self .testfile )
175
206
176
- ## responses
177
207
208
+ class TestExcelInput2OnBook :
209
+ def setUp (self ):
210
+ self .data = [['X' , 'Y' , 'Z' ], [1 , 2 , 3 ], [4 , 5 , 6 ]]
211
+ self .data1 = [['A' , 'B' , 'C' ], [1 , 2 , 3 ], [4 , 5 , 6 ]]
212
+ mydict = OrderedDict ()
213
+ mydict .update ({'sheet1' : self .data })
214
+ mydict .update ({'sheet2' : self .data1 })
215
+ book = pe .Book (mydict )
216
+ self .testfile = "testfile.xls"
217
+ book .save_as (self .testfile )
218
+
219
+ def test_get_book (self ):
220
+ myinput = TestExtendedInput ()
221
+ f = open (self .testfile ,'rb' )
222
+ result = myinput .get_book (field_name = ('xls' , f ))
223
+ assert result ["sheet1" ].to_array () == self .data
224
+ assert result ["sheet2" ].to_array () == self .data1
225
+ f .close ()
226
+
227
+
228
+ ## responses
178
229
class TestResponse :
179
230
def setUp (self ):
180
231
self .data = [
0 commit comments