fixed issue with overriding debug, and added test

This commit is contained in:
Edward Robinson
2012-10-25 21:17:03 +01:00
parent c30b3f1c65
commit 90b2c759e8
2 changed files with 16 additions and 3 deletions
+5 -3
View File
@@ -26,7 +26,10 @@ def url_for(endpoint, **values):
app = current_app
if 'S3_BUCKET_NAME' not in app.config:
raise ValueError("S3_BUCKET_NAME not found in app configuration.")
if app.debug and not app.config['USE_S3_DEBUG']:
return flask_url_for(endpoint, **values)
if endpoint == 'static' or endpoint.endswith('.static'):
scheme = 'http'
if app.config['S3_USE_HTTPS']:
@@ -189,6 +192,5 @@ class FlaskS3(object):
app.config.setdefault(k, v)
if app.config['USE_S3']:
if not app.debug or app.config['USE_S3_DEBUG']:
app.jinja_env.globals['url_for'] = url_for
app.jinja_env.globals['url_for'] = url_for
+11
View File
@@ -84,6 +84,17 @@ class UrlTests(unittest.TestCase):
exp = 'https://foo.s3.amazonaws.com/static/bah.js'
self.assertEquals(self.client_get(ufs).data, exp)
def test_url_for_debug(self):
"""Tests Flask-S3 behaviour in debug mode."""
self.app.debug = True
# static endpoint url_for in template
ufs = "{{url_for('static', filename='bah.js')}}"
exp = '/static/bah.js'
self.assertEquals(self.client_get(ufs).data, exp)
self.app.config['USE_S3_DEBUG'] = True
exp = 'https://foo.s3.amazonaws.com/static/bah.js'
self.assertEquals(self.client_get(ufs).data, exp)
def test_url_for_blueprint(self):
"""Tests that correct url formed for static asset in blueprint."""
# static endpoint url_for in template