mirror of https://github.com/pallets/flask.git
Fixed a whole bunch of resource warnings in the flask testsuite
This commit is contained in:
parent
47572c5b40
commit
eb622fb34f
|
|
@ -793,6 +793,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
with app.test_request_context():
|
||||
self.assert_equal(flask.url_for('static', filename='index.html'),
|
||||
'/static/index.html')
|
||||
rv.close()
|
||||
|
||||
def test_none_response(self):
|
||||
app = flask.Flask(__name__)
|
||||
|
|
|
|||
|
|
@ -172,8 +172,10 @@ class ModuleTestCase(FlaskTestCase):
|
|||
self.assert_equal(rv.data, b'Hello from the Admin')
|
||||
rv = c.get('/admin/static/test.txt')
|
||||
self.assert_equal(rv.data.strip(), b'Admin File')
|
||||
rv.close()
|
||||
rv = c.get('/admin/static/css/test.css')
|
||||
self.assert_equal(rv.data.strip(), b'/* nested file */')
|
||||
rv.close()
|
||||
|
||||
with app.test_request_context():
|
||||
self.assert_equal(flask.url_for('admin.static', filename='test.txt'),
|
||||
|
|
@ -354,8 +356,10 @@ class BlueprintTestCase(FlaskTestCase):
|
|||
self.assert_equal(rv.data, b'Hello from the Admin')
|
||||
rv = c.get('/admin/static/test.txt')
|
||||
self.assert_equal(rv.data.strip(), b'Admin File')
|
||||
rv.close()
|
||||
rv = c.get('/admin/static/css/test.css')
|
||||
self.assert_equal(rv.data.strip(), b'/* nested file */')
|
||||
rv.close()
|
||||
|
||||
# try/finally, in case other tests use this app for Blueprint tests.
|
||||
max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
|
||||
|
|
@ -405,6 +409,7 @@ class BlueprintTestCase(FlaskTestCase):
|
|||
rv = blueprint.send_static_file('index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 100)
|
||||
rv.close()
|
||||
finally:
|
||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
self.assert_equal(rv.mimetype, 'text/html')
|
||||
with app.open_resource('static/index.html') as f:
|
||||
self.assert_equal(rv.data, f.read())
|
||||
rv.close()
|
||||
|
||||
def test_send_file_xsendfile(self):
|
||||
app = flask.Flask(__name__)
|
||||
|
|
@ -170,6 +171,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
self.assert_equal(rv.headers['x-sendfile'],
|
||||
os.path.join(app.root_path, 'static/index.html'))
|
||||
self.assert_equal(rv.mimetype, 'text/html')
|
||||
rv.close()
|
||||
|
||||
def test_send_file_object(self):
|
||||
app = flask.Flask(__name__)
|
||||
|
|
@ -180,6 +182,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
with app.open_resource('static/index.html') as f:
|
||||
self.assert_equal(rv.data, f.read())
|
||||
self.assert_equal(rv.mimetype, 'text/html')
|
||||
rv.close()
|
||||
# mimetypes + etag
|
||||
self.assert_equal(len(captured), 2)
|
||||
|
||||
|
|
@ -192,6 +195,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
self.assert_in('x-sendfile', rv.headers)
|
||||
self.assert_equal(rv.headers['x-sendfile'],
|
||||
os.path.join(app.root_path, 'static/index.html'))
|
||||
rv.close()
|
||||
# mimetypes + etag
|
||||
self.assert_equal(len(captured), 2)
|
||||
|
||||
|
|
@ -202,6 +206,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
rv = flask.send_file(f)
|
||||
self.assert_equal(rv.data, b'Test')
|
||||
self.assert_equal(rv.mimetype, 'application/octet-stream')
|
||||
rv.close()
|
||||
# etags
|
||||
self.assert_equal(len(captured), 1)
|
||||
with catch_warnings() as captured:
|
||||
|
|
@ -209,6 +214,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
rv = flask.send_file(f, mimetype='text/plain')
|
||||
self.assert_equal(rv.data, b'Test')
|
||||
self.assert_equal(rv.mimetype, 'text/plain')
|
||||
rv.close()
|
||||
# etags
|
||||
self.assert_equal(len(captured), 1)
|
||||
|
||||
|
|
@ -218,6 +224,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
f = StringIO('Test')
|
||||
rv = flask.send_file(f)
|
||||
self.assert_not_in('x-sendfile', rv.headers)
|
||||
rv.close()
|
||||
# etags
|
||||
self.assert_equal(len(captured), 1)
|
||||
|
||||
|
|
@ -229,6 +236,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
rv = flask.send_file(f, as_attachment=True)
|
||||
value, options = parse_options_header(rv.headers['Content-Disposition'])
|
||||
self.assert_equal(value, 'attachment')
|
||||
rv.close()
|
||||
# mimetypes + etag
|
||||
self.assert_equal(len(captured), 2)
|
||||
|
||||
|
|
@ -238,6 +246,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
value, options = parse_options_header(rv.headers['Content-Disposition'])
|
||||
self.assert_equal(value, 'attachment')
|
||||
self.assert_equal(options['filename'], 'index.html')
|
||||
rv.close()
|
||||
|
||||
with app.test_request_context():
|
||||
rv = flask.send_file(StringIO('Test'), as_attachment=True,
|
||||
|
|
@ -247,6 +256,7 @@ class SendfileTestCase(FlaskTestCase):
|
|||
value, options = parse_options_header(rv.headers['Content-Disposition'])
|
||||
self.assert_equal(value, 'attachment')
|
||||
self.assert_equal(options['filename'], 'index.txt')
|
||||
rv.close()
|
||||
|
||||
def test_static_file(self):
|
||||
app = flask.Flask(__name__)
|
||||
|
|
@ -256,20 +266,24 @@ class SendfileTestCase(FlaskTestCase):
|
|||
rv = app.send_static_file('index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 12 * 60 * 60)
|
||||
rv.close()
|
||||
# Test again with direct use of send_file utility.
|
||||
rv = flask.send_file('static/index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 12 * 60 * 60)
|
||||
rv.close()
|
||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
|
||||
with app.test_request_context():
|
||||
# Test with static file handler.
|
||||
rv = app.send_static_file('index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 3600)
|
||||
rv.close()
|
||||
# Test again with direct use of send_file utility.
|
||||
rv = flask.send_file('static/index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 3600)
|
||||
rv.close()
|
||||
class StaticFileApp(flask.Flask):
|
||||
def get_send_file_max_age(self, filename):
|
||||
return 10
|
||||
|
|
@ -279,10 +293,12 @@ class SendfileTestCase(FlaskTestCase):
|
|||
rv = app.send_static_file('index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 10)
|
||||
rv.close()
|
||||
# Test again with direct use of send_file utility.
|
||||
rv = flask.send_file('static/index.html')
|
||||
cc = parse_cache_control_header(rv.headers['Cache-Control'])
|
||||
self.assert_equal(cc.max_age, 10)
|
||||
rv.close()
|
||||
|
||||
|
||||
class LoggingTestCase(FlaskTestCase):
|
||||
|
|
|
|||
Loading…
Reference in New Issue