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