Skip to content

Commit

Permalink
Fix default root handling with backend level configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
noirbizarre committed Mar 10, 2017
1 parent 749c534 commit 3d7beaa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion flask_fs/backends/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class LocalBackend(BaseBackend):
'''
@cached_property
def root(self):
return self.config.get('root') or os.path.join(current_app.config.get('FS_ROOT'), self.name)
return self.config.get('root') or os.path.join(self.default_root, self.name)

@cached_property
def default_root(self):
default_root = current_app.config.get('FS_ROOT')
return current_app.config.get('FS_LOCAL_ROOT', default_root)

def exists(self, filename):
dest = self.path(filename)
Expand Down
2 changes: 1 addition & 1 deletion flask_fs/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
BACKEND_PREFIX = 'FS_{0}_'

# Config keys that should be overwritten from backend config
BACKEND_EXCLUDED_CONFIG = ('BACKEND', 'URL')
BACKEND_EXCLUDED_CONFIG = ('BACKEND', 'URL', 'ROOT')


class Config(dict):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_local_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_default_root(self, app):
assert backend.root == root

def test_backend_root(self, app):
app.config['LOCAL_FS_ROOT'] = str(self.test_dir)
app.config['FS_LOCAL_ROOT'] = str(self.test_dir)
root = self.test_dir.join('default')
backend = LocalBackend('default', Config({}))
assert backend.root == root

0 comments on commit 3d7beaa

Please sign in to comment.