def test_configure_updates_settings_from_env_vars(env_var, env_val, setting_name, setting_val): environ = {env_var: env_val} if env_var else {} settings_from_conf = {'h.db_session_checks': True} config = configure(environ=environ, settings=settings_from_conf) assert config.registry.settings[setting_name] == setting_val
def create_app(global_config, **settings): config = configure(settings=settings) config.add_request_method(features.Client, name='feature', reify=True) config.set_authorization_policy(ACLAuthorizationPolicy()) policy = MultiAuthenticationPolicy([ TokenAuthenticationPolicy(callback=groupfinder), SessionAuthenticationPolicy(callback=groupfinder), ]) config.set_authentication_policy(policy) config.include('h.auth') config.include('h.sentry') config.include('h.stats') # We have to include models and db to set up sqlalchemy metadata. config.include('h.models') config.include('h.db') config.include('h.api.db') # We have to include search to set up the `request.es` property. config.include('h.api.search') config.include('h.streamer') return config.make_wsgi_app()
def create_app(global_config, **settings): config = configure(settings=settings) config.include('pyramid_services') config.include('h.auth') # Override the default authentication policy. config.set_authentication_policy('h.auth.WEBSOCKET_POLICY') config.include('h.authz') config.include('h.db') config.include('h.session') config.include('h.search') config.include('h.sentry') config.include('h.services') config.include('h.stats') # We include links in order to set up the alternative link registrations # for annotations. config.include('h.links') # And finally we add routes. Static routes are not resolvable by HTTP # clients, but can be used for URL generation within the websocket server. config.add_route('ws', '/ws') config.add_route('annotation', '/a/{id}', static=True) config.add_route('api.annotation', '/api/annotations/{id}', static=True) config.include('h.streamer') return config.make_wsgi_app()
def create_app(_global_config, **settings): config = configure(settings=settings) if os.environ.get("KILL_SWITCH_WEBSOCKET"): log.warning("Websocket kill switch has been enabled.") log.warning( "The switch is the environment variable 'KILL_SWITCH_WEBSOCKET'") log.warning( "No websocket functionality will work until the switch is disabled" ) # Add views to return messages so we don't get confused between # disabled and missing end-points in the logs config.scan("h.streamer.kill_switch_views") # Quit out early without configuring any routes etc. return config.make_wsgi_app() config.include("pyramid_services") config.include("h.auth") # Override the default authentication policy. config.set_authentication_policy("h.auth.WEBSOCKET_POLICY") config.include("h.authz") config.include("h.db") config.include("h.session") config.include("h.services") # We include links in order to set up the alternative link registrations # for annotations. config.include("h.links") # And finally we add routes. Static routes are not resolvable by HTTP # clients, but can be used for URL generation within the websocket server. config.add_route("ws", "/ws") config.add_route("annotation", "/a/{id}", static=True) config.add_route("api.annotation", "/api/annotations/{id}", static=True) config.scan("h.streamer.views") config.scan("h.streamer.streamer") config.add_tween( "h.streamer.tweens.close_db_session_tween_factory", over=["pyramid_exclog.exclog_tween_factory", pyramid.tweens.EXCVIEW], ) # Configure sentry config.add_settings({ "h_pyramid_sentry.filters": SENTRY_FILTERS, "h_pyramid_sentry.celery_support": True, }) config.include("h_pyramid_sentry") # Add support for logging exceptions whenever they arise config.include("pyramid_exclog") config.add_settings({"exclog.extra_info": True}) return config.make_wsgi_app()
def config(): from h.config import configure config = configure() config.registry.settings.update(TEST_SETTINGS) _drop_indices(settings=config.registry.settings) config.include('h.app') config.include('h.session') return config
def create_app(global_config, **settings): """ Create the h WSGI application. This function serves as a paste app factory. """ config = configure(settings=settings) config.include(__name__) return config.make_wsgi_app()
def config(): from h.config import configure from h.db import Session # Expire any previous database session Session.remove() config = configure() config.registry.settings.update(TEST_SETTINGS) _drop_indices(settings=config.registry.settings) config.include('h.app') config.include('h.session') return config
def test_configure_updates_settings_from_env_vars(env_var, env_val, setting_name, setting_val): environ = {env_var: env_val} if env_var else {} settings_from_conf = { "h.db_session_checks": True, # Required settings "es.url": "https://es6-search-cluster", "secret_key": "notasecret", "sqlalchemy.url": "postgres://user@dbhost/dbname", } config = configure(environ=environ, settings=settings_from_conf) assert config.registry.settings[setting_name] == setting_val
def test_configure_updates_settings_from_env_vars(env_var, env_val, setting_name, setting_val): environ = {env_var: env_val} if env_var else {} settings_from_conf = {'h.db_session_checks': True, # Required settings 'es.host': 'https://es1-search-cluster', 'es.url': 'https://es6-search-cluster', 'secret_key': 'notasecret', 'sqlalchemy.url': 'postgres://user@dbhost/dbname', } config = configure(environ=environ, settings=settings_from_conf) assert config.registry.settings[setting_name] == setting_val
def create_app(global_config, **settings): config = configure(settings=settings) config.add_request_method(features.Client, name='feature', reify=True) config.include('pyramid_services') config.include('h.auth') # Override the default authentication policy. config.set_authentication_policy('h.auth.WEBSOCKET_POLICY') config.include('h.authz') config.include('h.session') config.include('h.sentry') config.include('h.stats') # We have to include models and db to set up sqlalchemy metadata. config.include('h.models') config.include('h.db') # We have to include parts of the `memex` package in order to provide, # among other things: # # - the links service # - the default presenters (and their link registrations) # - the `request.es` property config.include('memex.links') config.include('memex.presenters') config.include('memex.search') # accounts provides the UserService config.include('h.accounts') # We include links in order to set up the alternative link registrations # for annotations. config.include('h.links') # We have to include nipsa to provide the NIPSA service config.include('h.nipsa') # And finally we add routes. Static routes are not resolvable by HTTP # clients, but can be used for URL generation within the websocket server. config.add_route('ws', '/ws') config.add_route('annotation', '/a/{id}', static=True) config.add_route('api.annotation', '/api/annotations/{id}', static=True) config.include('h.streamer') return config.make_wsgi_app()
def create_app(global_config, **settings): config = configure(settings=settings) config.add_request_method(features.Client, name="feature", reify=True) config.include("pyramid_services") config.include("h.auth") # Override the default authentication policy. config.set_authentication_policy("h.auth.WEBSOCKET_POLICY") config.include("h.authz") config.include("h.session") config.include("h.sentry") config.include("h.stats") # We have to include models and db to set up sqlalchemy metadata. config.include("h.models") config.include("h.db") # We have to include parts of the `memex` package in order to provide, # among other things: # # - the links service # - the default presenters (and their link registrations) # - the `request.es` property config.include("memex.links") config.include("memex.presenters") config.include("memex.search") # accounts provides the UserService config.include("h.accounts") # We include links in order to set up the alternative link registrations # for annotations. config.include("h.links") # We have to include nipsa to provide the NIPSA service config.include("h.nipsa") # And finally we add routes. Static routes are not resolvable by HTTP # clients, but can be used for URL generation within the websocket server. config.add_route("ws", "/ws") config.add_route("annotation", "/a/{id}", static=True) config.add_route("api.annotation", "/api/annotations/{id}", static=True) config.include("h.streamer") return config.make_wsgi_app()
def test_configure_updates_settings_from_env_vars(env_var, env_val, setting_name, setting_val): environ = {env_var: env_val} if env_var else {} settings_from_conf = { 'h.db_session_checks': True, # Required settings 'es.url': 'https://es6-search-cluster', 'secret_key': 'notasecret', 'sqlalchemy.url': 'postgres://user@dbhost/dbname', } config = configure(environ=environ, settings=settings_from_conf) assert config.registry.settings[setting_name] == setting_val
def test_configure_updates_settings_from_env_vars( env_var, env_val, setting_name, setting_val ): environ = {env_var: env_val} if env_var else {} settings_from_conf = { "h.db_session_checks": True, # Required settings "es.url": "https://es6-search-cluster", "secret_key": "notasecret", "sqlalchemy.url": "postgres://user@dbhost/dbname", } config = configure(environ=environ, settings=settings_from_conf) assert config.registry.settings[setting_name] == setting_val
def create_app(global_config, **settings): config = configure(settings=settings) config.add_request_method(features.Client, name='feature', reify=True) config.include('pyramid_services') config.include('h.auth') # Override the default authentication policy. config.set_authentication_policy('h.auth.WEBSOCKET_POLICY') config.include('h.authz') config.include('h.session') config.include('h.sentry') config.include('h.stats') # We have to include models and db to set up sqlalchemy metadata. config.include('h.models') config.include('h.db') # We have to include parts of the `memex` package in order to provide, # among other things: # # - the links service # - the default presenters (and their link registrations) # - the `request.es` property config.include('memex.links') config.include('memex.presenters') config.include('memex.search') # accounts provides the UserService config.include('h.accounts') # We include links in order to set up the alternative link registrations # for annotations. config.include('h.links') # We have to include nipsa to provide the NIPSA service config.include('h.nipsa') # And finally we add static routes which can be used for URL generation # within the websocket server. config.add_route('annotation', '/a/{id}', static=True) config.add_route('api.annotation', '/api/annotations/{id}', static=True) config.include('h.streamer') return config.make_wsgi_app()
def create_app(global_config, **settings): config = configure(settings=settings) config.add_tween( "h.streamer.close_db_session_tween_factory", over=["pyramid_exclog.exclog_tween_factory", pyramid.tweens.EXCVIEW], ) config.include("pyramid_services") config.include("h.auth") # Override the default authentication policy. config.set_authentication_policy("h.auth.WEBSOCKET_POLICY") config.include("h.authz") config.include("h.db") config.include("h.session") config.include("h.services") config.include("h.stats") # We include links in order to set up the alternative link registrations # for annotations. config.include("h.links") # And finally we add routes. Static routes are not resolvable by HTTP # clients, but can be used for URL generation within the websocket server. config.add_route("ws", "/ws") config.add_route("annotation", "/a/{id}", static=True) config.add_route("api.annotation", "/api/annotations/{id}", static=True) config.include("h.streamer") # Configure sentry config.add_settings( { "h_pyramid_sentry.filters": SENTRY_FILTERS, "h_pyramid_sentry.celery_support": True, } ) config.include("h_pyramid_sentry") # Add support for logging exceptions whenever they arise config.include("pyramid_exclog") config.add_settings({"exclog.extra_info": True}) return config.make_wsgi_app()
def create_app(global_config, **settings): config = configure(settings=settings) # We need to include `h.models` before pretty much everything else to # avoid the possibility that one of the imports below directly or # indirectly imports `memex.models`. See the comment at the top of # `h.models` for details. # # FIXME: h modules should not access `memex.models`, even indirectly, # except through `h.models`. config.include('h.models') config.include('pyramid_services') config.include('h.auth') # Override the default authentication policy. config.set_authentication_policy('h.auth.WEBSOCKET_POLICY') config.include('h.authz') config.include('h.db') config.include('h.session') config.include('h.search') config.include('h.sentry') config.include('h.stats') # We have to include parts of the `memex` package in order to provide # the links service. config.include('memex.links') # We include links in order to set up the alternative link registrations # for annotations. config.include('h.links') # Access to services config.include('h.services') # And finally we add routes. Static routes are not resolvable by HTTP # clients, but can be used for URL generation within the websocket server. config.add_route('ws', '/ws') config.add_route('annotation', '/a/{id}', static=True) config.add_route('api.annotation', '/api/annotations/{id}', static=True) config.include('h.streamer') return config.make_wsgi_app()
def create_app(global_config, **settings): config = configure(settings=settings) config.add_request_method(features.flag_enabled, name='feature') config.include('h.auth') config.include('h.sentry') config.include('h.stats') # We have to include models and db to set up sqlalchemy metadata. config.include('h.models') config.include('h.db') config.include('h.api.db') # We have to include search to set up the `request.es` property. config.include('h.api.search') config.include('h.streamer') return config.make_wsgi_app()
def test_configure_generates_secret_key_if_missing(): config = configure(environ={}, settings={}) assert 'secret_key' in config.registry.settings
def test_configure_doesnt_override_secret_key(): config = configure(environ={}, settings={'secret_key': 'foobar'}) assert config.registry.settings['secret_key'] == 'foobar'
def test_missing_secrets_doesnt_override_redis_sessions_secret(): config = configure(environ={}, settings={'redis.sessions.secret': 'isset'}) assert config.registry.settings['redis.sessions.secret'] == 'isset'
def test_configure_generates_redis_sessions_secret_if_missing(): config = configure(environ={}, settings={}) assert 'redis.sessions.secret' in config.registry.settings
def config(): from h.config import configure _drop_indices(settings=TEST_SETTINGS) config = configure(settings=TEST_SETTINGS) config.include('h.app') return config