Skip to content

Commit

Permalink
Merge 5c183ae into 0da3aa6
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinm committed Oct 8, 2014
2 parents 0da3aa6 + 5c183ae commit 32b0adb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion flask_collect/storage/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def run(self):
for bp, f, o in self:
destination = os.path.join(self.collect.static_root, o)
destination_dir = os.path.dirname(destination)
normalized_source = os.path.realpath(f)
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)

if destination in destination_list:
self.log("{0} already linked".format(destination))
skipped += 1
elif not os.path.exists(destination):
elif not os.path.exists(destination) or \
normalized_source != os.path.realpath(destination):
# the path is a link, but points to invalid location
if os.path.islink(destination):
os.remove(destination)
Expand Down
34 changes: 34 additions & 0 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,37 @@ def test_link_storage(self):

rmtree(test_static3)
rmtree(static_root)

def test_link_storage_update(self):
"""Test link storage update."""
app = Flask(__name__)

blueprint = Blueprint('test1', __name__, static_folder='static1')
app.register_blueprint(blueprint)

static_root = mkdtemp()

app.config['COLLECT_STATIC_ROOT'] = static_root
app.config['COLLECT_FILTER'] = partial(filter_, ['test1'])
app.config['COLLECT_STORAGE'] = 'flask.ext.collect.storage.link'

collect = Collect(app)
collect.collect()

# Make sure a new link has been created pointing to test1
with open(op.join(static_root, 'test.css'), 'r') as file_:
self.assertTrue('body { color: blue; }' in file_.read())


blueprint = Blueprint('test3', __name__, static_folder='static3')
app.register_blueprint(blueprint)

app.config['COLLECT_FILTER'] = partial(filter_, ['test3', 'test1'])
collect = Collect(app)
collect.collect()

# Make sure a new link has been created pointing to test3
with open(op.join(static_root, 'test.css'), 'r') as file_:
self.assertTrue('body { color: red; }' in file_.read())

rmtree(static_root)

0 comments on commit 32b0adb

Please sign in to comment.