mirror of
https://github.com/wassname/flask-s3.git
synced 2026-09-10 12:00:58 +08:00
A fix for #2. Slightly different approach to @rdegges as static_folder is the main issue. Plus some tests.
This commit is contained in:
+3
-2
@@ -42,14 +42,15 @@ def url_for(endpoint, **values):
|
||||
|
||||
def _bp_static_url(blueprint):
|
||||
""" builds the absolute url path for a blueprint's static folder """
|
||||
return u'%s%s' % (blueprint.url_prefix or '', blueprint.static_url_path)
|
||||
return u'%s%s' % (blueprint.url_prefix or '', blueprint.static_url_path or '')
|
||||
|
||||
def _gather_files(app, hidden):
|
||||
""" Gets all files in static folders and returns in dict."""
|
||||
dirs = [(unicode(app.static_folder), app.static_url_path)]
|
||||
if hasattr(app, 'blueprints'):
|
||||
blueprints = app.blueprints.values()
|
||||
bp_details = lambda x: (x.static_folder, _bp_static_url(x))
|
||||
dirs.extend([bp_details(x) for x in app.blueprints.values()])
|
||||
dirs.extend([bp_details(x) for x in blueprints if x.static_folder])
|
||||
|
||||
valid_files = defaultdict(list)
|
||||
for static_folder, static_url_loc in dirs:
|
||||
|
||||
@@ -109,15 +109,15 @@ class S3Tests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.app = Mock(spec=Flask)
|
||||
|
||||
|
||||
def test__bp_static_url(self):
|
||||
""" Tests test__bp_static_url """
|
||||
bps = [Mock(static_url_path='/foo', url_prefix=None),
|
||||
Mock(static_url_path='/b/bar', url_prefix='/pref')]
|
||||
expected = [u'/foo', u'/pref/b/bar']
|
||||
Mock(static_url_path=None, url_prefix='/pref'),
|
||||
Mock(static_url_path='/b/bar', url_prefix='/pref'),
|
||||
Mock(static_url_path=None, url_prefix=None)]
|
||||
expected = [u'/foo', u'/pref', u'/pref/b/bar', u'']
|
||||
self.assertEquals(expected, [flask_s3._bp_static_url(x) for x in bps])
|
||||
|
||||
|
||||
@patch('os.walk')
|
||||
@patch('os.path.isdir')
|
||||
def test__gather_files(self, path_mock, os_mock):
|
||||
@@ -129,7 +129,9 @@ class S3Tests(unittest.TestCase):
|
||||
url_prefix=None)
|
||||
bp_b = Mock(static_folder='/home/zoo', static_url_path='/b/bar',
|
||||
url_prefix=None)
|
||||
self.app.blueprints = { 'a': bp_a, 'b': bp_b}
|
||||
bp_c = Mock(static_folder=None)
|
||||
|
||||
self.app.blueprints = { 'a': bp_a, 'b': bp_b, 'c': bp_c}
|
||||
dirs = { '/home': [('/home', None, ['.a'])],
|
||||
'/home/bar': [('/home/bar', None, ['b'])],
|
||||
'/home/zoo': [('/home/zoo', None, ['c']),
|
||||
|
||||
Reference in New Issue
Block a user