Permalink
Browse files

Fix edge-case of #36, add tests.

  • Loading branch information...
1 parent 2639ce0 commit 82ce4dc87ac0ddf99642b51f990988da5c2d3c6d @miracle2k committed Jan 4, 2013
Showing with 25 additions and 1 deletion.
  1. +5 −1 src/flask_assets.py
  2. +20 −0 tests/test_integration.py
View
6 src/flask_assets.py
@@ -214,13 +214,17 @@ def convert_item_to_flask_url(self, item, filepath=None):
the Flask static url. By doing so it takes into account
blueprints, i.e. in the aformentioned example,
``foo`` may reference a blueprint.
+
+ If an absolute path is given via ``filepath``, it will be
+ used instead. This is needed because ``item`` may be a
+ glob instruction that was resolved to multiple files.
"""
directory, rel_path, endpoint = self.split_prefix(item)
if filepath is not None:
filename = filepath[len(directory)+1:]
else:
- filename = item
+ filename = rel_path
ctx = None
if not _request_ctx_stack.top:
View
20 tests/test_integration.py
@@ -135,6 +135,13 @@ def test_existing_request_object_used(self):
'/', environ_overrides={'SCRIPT_NAME': '/yourapp'}):
assert Bundle('foo').urls(self.env) == ['/yourapp/app_static/foo']
+ def test_glob(self):
+ """Make sure url generation works with globs."""
+ self.app.static_folder = self.tempdir
+ self.create_files({'a.js': 'foo', 'b.js': 'bar'})
+ assert self.mkbundle('*.js').urls(self.env) == [
+ '/app_static/a.js', '/app_static/b.js']
+
class TestUrlAndDirectoryWithInitApp(object):
"""[Regression] Make sure the automatic "directory" and "url"
@@ -209,6 +216,19 @@ def test_blueprint_output(self):
self.mkbundle('foo', filters='rjsmin', output='module/out').build()
assert self.get('module-static/out') == 'function bla(){var a;}'
+ def test_blueprint_urls(self):
+ """Urls to blueprint files are generated correctly."""
+ self.make_blueprint('module', static_folder='static',
+ static_url_path='/rasputin')
+
+ # source urls
+ assert self.mkbundle('module/foo').urls() == ['/rasputin/foo']
+
+ # output urls - env settings are to not touch filesystem
+ self.env.auto_build = False
+ self.env.expire = False
+ assert self.mkbundle(output='module/out', debug=False).urls() == ['/rasputin/out']
+
def test_cssrewrite(self):
"""Make sure cssrewrite works with Blueprints.
"""

0 comments on commit 82ce4dc

Please sign in to comment.