def test_expandvars_dict(): """Test that env vars are added to settings dict.""" from pyramid_heroku import expandvars_dict import os os.environ["FOO"] = "foo" os.environ["BAR"] = "${FOO}bar" settings = { "test_boolean": "true", "test_integer": "1337", "test_string": "'asdfg hjkl'", "test_none": "None", "test_set": "('test', 'tIsT')", "test_multi_set": "(('fOo', 'BaRrAr'), ('asd', 'AsD'))", "test_empty": "", "test_env": "${FOO}", "test_env_nested": "${BAR}", } expanded_settings = { "test_boolean": True, "test_integer": 1337, "test_string": "asdfg hjkl", "test_none": None, "test_set": ("test", "tIsT"), "test_multi_set": (("fOo", "BaRrAr"), ("asd", "AsD")), "test_empty": None, "test_env": "foo", "test_env_nested": "foobar", } assert expanded_settings == expandvars_dict(settings)
def main(global_config: t.Dict[str, str], **settings: str) -> Router: """Return a Pyramid WSGI application.""" # Expand environment variables in .ini files settings = expandvars_dict(settings) # Configure Pyramid # TODO: can we configure root_factory in auth.py? # config.set_root_factory(root_factory) maybe? config = Configurator(settings=settings, root_factory="conduit.auth.RootFactory") configure(config) # Verify that DB schema is migrated to latest version # TODO: If this check is removed, the app breaks. The culprit is somewhere # in pyramid_deferred_sql: the request wrapper that sets the `read_only` # request property gets correctly called and then when the connections is # set to be marked as read_only, sqla fails with # `set_session cannot be used inside a transaction` # Using check_db_migrated, database transaction is already started, and # setting the session to read_only is skipped, which masks the bug if not global_config.get("SKIP_CHECK_DB_MIGRATED"): check_db_migrated(config, global_config) # Up, Up and Away! return config.make_wsgi_app()
def test_expandvars_dict(): """Test that env vars are added to settings dict.""" from pyramid_heroku import expandvars_dict import os os.environ["FOO"] = "foo" os.environ["BAR"] = "bar" os.environ["NESTED"] = "${FOO}bar" settings = { "test_boolean": "true", "test_integer": "1337", "test_string": "'asdfg hjkl'", "test_none": "None", "test_set": "('test', 'tIsT')", "test_multi_set": "(('fOo', 'BaRrAr'), ('asd', 'AsD'))", "test_empty": "", "test_env": "${FOO}", "test_env_nested": "${NESTED}", "test_dollar": "$", "test_endswith_dollar": "BAR$", "test_simple_variable": "$FOO", "test_multi_variables": "$FOO${BAR}", "test_default_set": "${FOO:-default}", "test_default_unset": "${BUZ:-default}", "test_substitute_set": "${FOO:+default}", "test_substitute_unset": "${BUZ:+default}", "test_offset": "${BAR:2}", "test_offset_length": "${BAR:1:3}", } expanded_settings = { "test_boolean": True, "test_integer": 1337, "test_string": "asdfg hjkl", "test_none": None, "test_set": ("test", "tIsT"), "test_multi_set": (("fOo", "BaRrAr"), ("asd", "AsD")), "test_empty": "", "test_env": "foo", "test_env_nested": "foobar", "test_dollar": "$", "test_endswith_dollar": "BAR$", "test_simple_variable": "foo", "test_multi_variables": "foobar", "test_default_set": "foo", "test_default_unset": "default", "test_substitute_set": "default", "test_substitute_unset": "", "test_offset": "r", "test_offset_length": "ar", } assert expanded_settings == expandvars_dict(settings)
def main(global_config: t.Dict[str, str], **settings: str) -> Router: """Return a Pyramid WSGI application.""" # Support for turning off alembic DB checks in certain scripts if global_config.get("SKIP_CHECK_DB_MIGRATED"): settings["SKIP_CHECK_DB_MIGRATED"] = global_config[ "SKIP_CHECK_DB_MIGRATED"] # Expand environment variables in .ini files settings = expandvars_dict(settings) # Configure Pyramid config = Configurator(settings=settings, root_factory="getoffmylawn.auth.RootFactory") configure(config) # Up, Up and Away! return config.make_wsgi_app()
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ connectable = engine_from_config( expandvars_dict(config.get_section("app:conduit")), prefix="sqlalchemy.", poolclass=pool.NullPool, ) with connectable.connect() as connection: context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations()
def main(global_config: t.Dict[str, str], **settings: str) -> Router: """Return a Pyramid WSGI application.""" # Support for turning off alembic DB checks in certain scripts if global_config.get("SKIP_CHECK_DB_MIGRATED"): settings["SKIP_CHECK_DB_MIGRATED"] = global_config["SKIP_CHECK_DB_MIGRATED"] # Expand environment variables in .ini files settings = expandvars_dict(settings) # Configure Pyramid # TODO: can we configure root_factory in auth.py? # config.set_root_factory(root_factory) maybe? config = Configurator( settings=settings, root_factory="{{cookiecutter.project_slug}}.auth.RootFactory" ) configure(config) # Up, Up and Away! return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application.""" settings = expandvars_dict(settings) with Configurator(settings=settings) as config: config.include('.models') config.include('.i18n') config.include('pyramid_jinja2') config.include('pyramid_raven') config.include('.routes') config.include('.security') config.scan() # Defining sessions session_secret = settings['session.secret'] session_factory = SignedCookieSessionFactory(session_secret) config.set_session_factory(session_factory) return config.make_wsgi_app()