@@ -159,6 +159,7 @@ def test_send_file_regular(self):
159
159
self .assert_equal (rv .mimetype , 'text/html' )
160
160
with app .open_resource ('static/index.html' ) as f :
161
161
self .assert_equal (rv .data , f .read ())
162
+ rv .close ()
162
163
163
164
def test_send_file_xsendfile (self ):
164
165
app = flask .Flask (__name__ )
@@ -170,6 +171,7 @@ def test_send_file_xsendfile(self):
170
171
self .assert_equal (rv .headers ['x-sendfile' ],
171
172
os .path .join (app .root_path , 'static/index.html' ))
172
173
self .assert_equal (rv .mimetype , 'text/html' )
174
+ rv .close ()
173
175
174
176
def test_send_file_object (self ):
175
177
app = flask .Flask (__name__ )
@@ -180,6 +182,7 @@ def test_send_file_object(self):
180
182
with app .open_resource ('static/index.html' ) as f :
181
183
self .assert_equal (rv .data , f .read ())
182
184
self .assert_equal (rv .mimetype , 'text/html' )
185
+ rv .close ()
183
186
# mimetypes + etag
184
187
self .assert_equal (len (captured ), 2 )
185
188
@@ -192,6 +195,7 @@ def test_send_file_object(self):
192
195
self .assert_in ('x-sendfile' , rv .headers )
193
196
self .assert_equal (rv .headers ['x-sendfile' ],
194
197
os .path .join (app .root_path , 'static/index.html' ))
198
+ rv .close ()
195
199
# mimetypes + etag
196
200
self .assert_equal (len (captured ), 2 )
197
201
@@ -202,13 +206,15 @@ def test_send_file_object(self):
202
206
rv = flask .send_file (f )
203
207
self .assert_equal (rv .data , b'Test' )
204
208
self .assert_equal (rv .mimetype , 'application/octet-stream' )
209
+ rv .close ()
205
210
# etags
206
211
self .assert_equal (len (captured ), 1 )
207
212
with catch_warnings () as captured :
208
213
f = StringIO ('Test' )
209
214
rv = flask .send_file (f , mimetype = 'text/plain' )
210
215
self .assert_equal (rv .data , b'Test' )
211
216
self .assert_equal (rv .mimetype , 'text/plain' )
217
+ rv .close ()
212
218
# etags
213
219
self .assert_equal (len (captured ), 1 )
214
220
@@ -218,6 +224,7 @@ def test_send_file_object(self):
218
224
f = StringIO ('Test' )
219
225
rv = flask .send_file (f )
220
226
self .assert_not_in ('x-sendfile' , rv .headers )
227
+ rv .close ()
221
228
# etags
222
229
self .assert_equal (len (captured ), 1 )
223
230
@@ -229,6 +236,7 @@ def test_attachment(self):
229
236
rv = flask .send_file (f , as_attachment = True )
230
237
value , options = parse_options_header (rv .headers ['Content-Disposition' ])
231
238
self .assert_equal (value , 'attachment' )
239
+ rv .close ()
232
240
# mimetypes + etag
233
241
self .assert_equal (len (captured ), 2 )
234
242
@@ -238,6 +246,7 @@ def test_attachment(self):
238
246
value , options = parse_options_header (rv .headers ['Content-Disposition' ])
239
247
self .assert_equal (value , 'attachment' )
240
248
self .assert_equal (options ['filename' ], 'index.html' )
249
+ rv .close ()
241
250
242
251
with app .test_request_context ():
243
252
rv = flask .send_file (StringIO ('Test' ), as_attachment = True ,
@@ -247,6 +256,7 @@ def test_attachment(self):
247
256
value , options = parse_options_header (rv .headers ['Content-Disposition' ])
248
257
self .assert_equal (value , 'attachment' )
249
258
self .assert_equal (options ['filename' ], 'index.txt' )
259
+ rv .close ()
250
260
251
261
def test_static_file (self ):
252
262
app = flask .Flask (__name__ )
@@ -256,20 +266,24 @@ def test_static_file(self):
256
266
rv = app .send_static_file ('index.html' )
257
267
cc = parse_cache_control_header (rv .headers ['Cache-Control' ])
258
268
self .assert_equal (cc .max_age , 12 * 60 * 60 )
269
+ rv .close ()
259
270
# Test again with direct use of send_file utility.
260
271
rv = flask .send_file ('static/index.html' )
261
272
cc = parse_cache_control_header (rv .headers ['Cache-Control' ])
262
273
self .assert_equal (cc .max_age , 12 * 60 * 60 )
274
+ rv .close ()
263
275
app .config ['SEND_FILE_MAX_AGE_DEFAULT' ] = 3600
264
276
with app .test_request_context ():
265
277
# Test with static file handler.
266
278
rv = app .send_static_file ('index.html' )
267
279
cc = parse_cache_control_header (rv .headers ['Cache-Control' ])
268
280
self .assert_equal (cc .max_age , 3600 )
281
+ rv .close ()
269
282
# Test again with direct use of send_file utility.
270
283
rv = flask .send_file ('static/index.html' )
271
284
cc = parse_cache_control_header (rv .headers ['Cache-Control' ])
272
285
self .assert_equal (cc .max_age , 3600 )
286
+ rv .close ()
273
287
class StaticFileApp (flask .Flask ):
274
288
def get_send_file_max_age (self , filename ):
275
289
return 10
@@ -279,10 +293,12 @@ def get_send_file_max_age(self, filename):
279
293
rv = app .send_static_file ('index.html' )
280
294
cc = parse_cache_control_header (rv .headers ['Cache-Control' ])
281
295
self .assert_equal (cc .max_age , 10 )
296
+ rv .close ()
282
297
# Test again with direct use of send_file utility.
283
298
rv = flask .send_file ('static/index.html' )
284
299
cc = parse_cache_control_header (rv .headers ['Cache-Control' ])
285
300
self .assert_equal (cc .max_age , 10 )
301
+ rv .close ()
286
302
287
303
288
304
class LoggingTestCase (FlaskTestCase ):
0 commit comments