Skip to content

Commit

Permalink
SWPY-1044 make possible to pass custom configurator
Browse files Browse the repository at this point in the history
Also combine the arguments for passing test settings and
regular settings into one keyword argument called settings.
If in the settings is passed the key 'setting' and is True
then include the testing mailer, otherwise the regular one.
  • Loading branch information
ev-agelos committed Sep 12, 2017
1 parent 26a7666 commit b29b8c2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
37 changes: 20 additions & 17 deletions spynl/main/__init__.py
Expand Up @@ -22,21 +22,33 @@
from spynl.main.locale import TemplateTranslations


def main(global_config, test_settings=None, **settings):
class ConfigCommited(object):
""" Event to signal that configurator finished and commited."""

def __init__(self, config):
self.config = config


def main(global_config, config=None, **settings):
"""
Return a Pyramid WSGI application.
Before that, we tell plugins how to add a view and tell views which
renderer to use. And we take care of test settings. Then, we initialise the
main plugins and the external plugins (which are not in this repository).
"""
# load (test) settings
config = Configurator(settings=settings)
config.add_settings({'spynl.ops.start_time': now()})
if config is None:
config = Configurator(settings=settings)
main_includeme(config)

config.commit()
config.registry.notify(ConfigCommited(config))

return config.make_wsgi_app()


if test_settings:
for key, value in test_settings.items():
config.add_settings({key: value})
def main_includeme(config):
config.add_settings({'spynl.ops.start_time': now()})

# Add spynl.main's view derivers
config.add_view_deriver(validate_json_schema)
Expand Down Expand Up @@ -89,13 +101,4 @@ def main(global_config, test_settings=None, **settings):
},
})

# initialise mailer, use dummy mailer for tests
if test_settings:
config.include('pyramid_mailer.testing')
else:
config.include('pyramid_mailer')

config.commit()
config.registry.notify(plugins.PluginsLoaded(config))

return config.make_wsgi_app()
return config
6 changes: 0 additions & 6 deletions spynl/main/plugins.py
Expand Up @@ -2,12 +2,6 @@
from pkg_resources import iter_entry_points # pylint: disable=E0611


class PluginsLoaded(object):
""" Event to signal that all plugins have been loaded"""
def __init__(self, config):
self.config = config


def main(config):
"""initialize this module, find all plugins and include them"""
installed_plugins = {
Expand Down
10 changes: 5 additions & 5 deletions spynl/tests/conftest.py
Expand Up @@ -20,11 +20,10 @@ def settings():
return {'spynl.pretty': '1',
'enable_plugins': [],
'pyramid.debug_authorization': 'false',
'pyramid.default_locale_name': 'en',
'pyramid.default_locale_name': 'nl',
'pyramid.reload_templates': 'true',
'spynl.domain': 'localhost',
'spynl.languages': 'en,nl',
'default_locale_name': 'nl',
'spynl.schemas': 'spynl-schemas',
'pyramid.debug_notfound': 'false',
'pyramid.debug_templates': 'true',
Expand All @@ -34,7 +33,8 @@ def settings():
'spynl.dev_origin_whitelist':
'http://0.0.0.0:9001,chrome-extension:// ',
'mail.host': 'smtp.fakehost.com', 'mail.ssl': 'false',
'mail.sender': 'info@spynl.com'}
'mail.sender': 'info@spynl.com',
'pyramid.includes': 'pyramid_mailer.testing'}


@pytest.fixture(scope="session")
Expand All @@ -49,7 +49,7 @@ def app(settings):
add_decode_function(config, decode_date, ['date'])
add_encode_function(config, encode_date, datetime)
add_encode_function(config, encode_boolean, bool)
spynl_app = main(None, test_settings=settings)
spynl_app = main(None, **settings)
webtest_app = TestApp(spynl_app)

return webtest_app
Expand All @@ -60,7 +60,7 @@ def app_factory():
"""Return a basic factory app maker to be able to pass custom settings."""
def make_app(settings):
"""Return the maker app."""
spynl_app = main(None, test_settings=settings)
spynl_app = main(None, **settings)
webtest_app = TestApp(spynl_app)
return webtest_app
return make_app
Expand Down

0 comments on commit b29b8c2

Please sign in to comment.