mirror of
https://github.com/wassname/flask-s3.git
synced 2026-06-27 15:50:06 +08:00
fixed issue with overriding debug, and added test
This commit is contained in:
+5
-3
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user