Skip to content

Commit

Permalink
Fix edge-case of #36, add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
miracle2k committed Jan 4, 2013
1 parent 2639ce0 commit 82ce4dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/flask_assets.py
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_integration.py
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
"""
Expand Down

0 comments on commit 82ce4dc

Please sign in to comment.