Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Add parameter on Server to override tornado's application settings
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsobreira committed Mar 16, 2012
1 parent 363b1c0 commit 4ccfbc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions oauth2u/server/__init__.py
Expand Up @@ -10,12 +10,13 @@
class Server(object):

def __init__(self, port=8000, plugins_directories=(), handlers_directories=(),
log_config=None, database=None):
log_config=None, database=None, application_settings=None):
self.port = port
self.application = None
self.database = database or MemoryDataBase()
self.load_plugins(plugins_directories)
self.load_handlers(handlers_directories)
self.custom_application_settings = application_settings or {}
log.configure(**log_config or {})

@property
Expand All @@ -40,8 +41,10 @@ def create_application(self):

@property
def application_settings(self):
return dict(debug=True,
cookie_secret=str(uuid.uuid4()))
default_settings = {'debug': True,
'cookie_secret': str(uuid.uuid4())}
default_settings.update(self.custom_application_settings)
return default_settings

def start_ioloop(self):
log.info('Server listening on port %s', self.port)
Expand Down
6 changes: 6 additions & 0 deletions tests/server/test_server.py
Expand Up @@ -36,3 +36,9 @@ def test_should_override_default_log_parameters(monkeypatch):

assert 1 == log_mock.configure.call_count
log_mock.configure.assert_called_with(format='%(message)s')

def test_should_allow_to_application_settings():
server = oauth2u.Server(application_settings={'static_path': '/foo/bar'})

assert 'static_path' in server.application_settings

0 comments on commit 4ccfbc3

Please sign in to comment.