def staticdir(tmpdir): tmpdir = tmpdir.join('libweasyl-staticdir') configure_libweasyl( dbsession=sessionmaker, not_found_exception=NotFound, base_file_path=tmpdir.strpath, staff_config_dict={}, media_link_formatter_callback=media_link_formatter.format_media_link, ) return tmpdir
media, middleware, ) from weasyl.controllers.routes import setup_routes_and_views from weasyl.wsgi import wsgi_app cache.region.configure( 'dogpile.cache.memory', wrap=[ThreadCacheProxy, JSONProxy], ) define.metric = lambda *a, **kw: None configure_libweasyl( dbsession=define.sessionmaker, not_found_exception=HTTPNotFound, base_file_path=macro.MACRO_STORAGE_ROOT, staff_config_dict={}, media_link_formatter_callback=media.format_media_link, ) @pytest.fixture(scope='session', autouse=True) def setupdb(request): define.engine.execute('DROP SCHEMA public CASCADE') define.engine.execute('CREATE SCHEMA public') define.engine.execute('CREATE EXTENSION HSTORE') define.engine.execute('CREATE EXTENSION FUZZYSTRMATCH') # hstore oids changed; de-memoize them and create new connections define.engine.dialect._hstore_oids = psycopg2.PGDialect_psycopg2._hstore_oids.__get__( define.engine.dialect)
import web from weasyl import config config._in_test = True # noqa from libweasyl.configuration import configure_libweasyl from libweasyl.models.meta import registry from weasyl import cache, define, macro, media cache.region.configure('dogpile.cache.memory') define.metric = lambda *a, **kw: None configure_libweasyl( dbsession=define.sessionmaker, not_found_exception=web.notfound, base_file_path='testing', staff_config_path=macro.MACRO_SYS_STAFF_CONFIG_PATH, media_link_formatter_callback=media.format_media_link, ) @pytest.fixture(scope='session', autouse=True) def setupdb(request): db = define.connect() db.execute('DROP SCHEMA public CASCADE') db.execute('CREATE SCHEMA public') db.execute('CREATE EXTENSION HSTORE') define.meta.create_all(define.engine) @pytest.fixture(autouse=True)
mw._delegate = app._delegate app._delegate = mw.endpoint_recording_delegate def weasyl_404(): userid = d.get_userid() return web.notfound(d.errorpage( userid, "**404!** The page you requested could not be found.")) app.notfound = weasyl_404 wsgi_app = app.wsgifunc() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'): from werkzeug.contrib.profiler import ProfilerMiddleware wsgi_app = ProfilerMiddleware( wsgi_app, profile_dir=m.MACRO_SYS_BASE_PATH + 'profile-stats') if d.config_obj.has_option('sentry', 'dsn'): wsgi_app = mw.SentryEnvironmentMiddleware(wsgi_app, d.config_obj.get('sentry', 'dsn')) configure_libweasyl( dbsession=d.sessionmaker, not_found_exception=web.notfound, base_file_path=m.MACRO_SYS_BASE_PATH, staff_config_path=m.MACRO_SYS_STAFF_CONFIG_PATH, media_link_formatter_callback=format_media_link, )
setup_routes_and_views(config) # Setup properties and methods for request objects. config.add_request_method(mw.pg_connection_request_property, name='pg_connection', reify=True) config.add_request_method(mw.userid_request_property, name='userid', reify=True) config.add_request_method(mw.log_exc_request_method, name='log_exc') config.add_request_method(mw.web_input_request_method, name='web_input') config.add_request_method(mw.set_cookie_on_response) config.add_request_method(mw.delete_cookie_on_response) wsgi_app = config.make_wsgi_app() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'): from werkzeug.contrib.profiler import ProfilerMiddleware wsgi_app = ProfilerMiddleware( wsgi_app, profile_dir=m.MACRO_SYS_BASE_PATH + 'profile-stats') if d.config_obj.has_option('sentry', 'dsn'): wsgi_app = mw.SentryEnvironmentMiddleware(wsgi_app, d.config_obj.get('sentry', 'dsn')) configure_libweasyl( dbsession=d.sessionmaker, not_found_exception=HTTPNotFound, base_file_path=m.MACRO_SYS_BASE_PATH, staff_config_dict=read_staff_yaml.load_staff_dict(), media_link_formatter_callback=format_media_link, )
login, macro, media, middleware ) from weasyl.wsgi import wsgi_app cache.region.configure('dogpile.cache.memory') define.metric = lambda *a, **kw: None configure_libweasyl( dbsession=define.sessionmaker, not_found_exception=HTTPNotFound, base_file_path=macro.MACRO_STORAGE_ROOT, staff_config_dict={}, media_link_formatter_callback=media.format_media_link, ) @pytest.fixture(scope='session', autouse=True) def setupdb(request): define.engine.execute('DROP SCHEMA public CASCADE') define.engine.execute('CREATE SCHEMA public') define.engine.execute('CREATE EXTENSION HSTORE') define.engine.execute('CREATE EXTENSION FUZZYSTRMATCH') # hstore oids changed; de-memoize them and create new connections define.engine.dialect._hstore_oids = psycopg2.PGDialect_psycopg2._hstore_oids.__get__(define.engine.dialect) define.engine.dispose()
config.add_request_method(mw.pg_connection_request_property, name='pg_connection', reify=True) config.add_request_method(mw.userid_request_property, name='userid', reify=True) config.add_request_method(mw.log_exc_request_method, name='log_exc') config.add_request_method(mw.web_input_request_method, name='web_input') config.add_request_method(mw.set_cookie_on_response) config.add_request_method(mw.delete_cookie_on_response) wsgi_app = config.make_wsgi_app() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'): from werkzeug.contrib.profiler import ProfilerMiddleware wsgi_app = ProfilerMiddleware(wsgi_app, profile_dir=m.MACRO_STORAGE_ROOT + 'profile-stats') if d.config_obj.has_option('sentry', 'dsn'): wsgi_app = mw.SentryEnvironmentMiddleware( wsgi_app, d.config_obj.get('sentry', 'dsn')) configure_libweasyl( dbsession=d.sessionmaker, not_found_exception=HTTPNotFound, base_file_path=m.MACRO_STORAGE_ROOT, staff_config_dict=staff_config.load(), media_link_formatter_callback=format_media_link, )
from weasyl import config config._in_test = True # noqa from libweasyl.configuration import configure_libweasyl from libweasyl.models.tables import metadata from weasyl import cache, define, emailer, macro, media, middleware cache.region.configure('dogpile.cache.memory') define.metric = lambda *a, **kw: None configure_libweasyl( dbsession=define.sessionmaker, not_found_exception=HTTPNotFound, base_file_path='testing', staff_config_dict={}, media_link_formatter_callback=media.format_media_link, ) @pytest.fixture(scope='session', autouse=True) def setupdb(request): define.engine.execute('DROP SCHEMA public CASCADE') define.engine.execute('CREATE SCHEMA public') define.engine.execute('CREATE EXTENSION HSTORE') # hstore oids changed; de-memoize them and create new connections define.engine.dialect._hstore_oids = psycopg2.PGDialect_psycopg2._hstore_oids.__get__(define.engine.dialect) define.engine.dispose()
def make_app(global_config, **settings): hacks.install() settings['deform_jinja2.template_search_path'] = 'weasyl:widgets' settings['jinja2.filters'] = """ asset_path = weasyl.filters.asset_path_filter json = weasyl.filters.json_filter markdown = weasyl.filters.markdown_filter relative_date = weasyl.filters.relative_date """ config = Configurator( settings=settings, session_factory=WeasylSession, root_factory=RootResource, ) configure_db(config, settings) configure_libweasyl( dbsession=DBSession, not_found_exception=httpexceptions.HTTPNotFound, base_file_path=settings['weasyl.static_root'], media_link_formatter_callback=format_media_link, ) config.include('pyramid_tm') config.include('pyramid_jinja2') config.include('pyramid_deform') config.include('deform_jinja2') config.add_static_view(name='static', path='weasyl:static') config.add_jinja2_search_path('weasyl:templates') config.add_view_predicate('api', predicates.APIPredicate) config.add_request_method(path_for) config.add_request_method(format_datetime) config.add_request_method(make_asset_path_finder()) config.add_request_method(current_user, reify=True) config.add_request_method(is_api_request, reify=True) config.add_request_method(is_debug_on, reify=True) config.add_request_method(login_forms, reify=True) config.add_tween('weasyl.sessions.session_tween_factory', under='pyramid_tm.tm_tween_factory') configure_urls(config) json_renderer = NoLeadingUnderscoresJSON() json_renderer.add_adapter(datetime.datetime, datetime_adapter) json_renderer.add_adapter(arrow.Arrow, datetime_adapter) config.add_renderer('json', json_renderer) auth_stack = AuthenticationStackPolicy(callback=authorization.groupfinder) auth_stack.add_policy( 'api_key', authentication.APIKeyAuthenticationPolicy( callback=authorization.groupfinder)) auth_stack.add_policy( 'session', SessionAuthenticationPolicy(prefix='', callback=authorization.groupfinder)) config.set_authentication_policy(auth_stack) config.set_authorization_policy( authorization.DelegatedAuthorizationPolicy()) config.scan('weasyl.views', ignore='weasyl.views.test') return config.make_wsgi_app()
def make_app(global_config, **settings): hacks.install() settings['deform_jinja2.template_search_path'] = 'weasyl:widgets' settings['jinja2.filters'] = """ asset_path = weasyl.filters.asset_path_filter json = weasyl.filters.json_filter markdown = weasyl.filters.markdown_filter relative_date = weasyl.filters.relative_date """ config = Configurator( settings=settings, session_factory=WeasylSession, root_factory=RootResource, ) configure_db(config, settings) configure_libweasyl( dbsession=DBSession, not_found_exception=httpexceptions.HTTPNotFound, base_file_path=settings['weasyl.static_root'], media_link_formatter_callback=format_media_link, ) config.include('pyramid_tm') config.include('pyramid_jinja2') config.include('pyramid_deform') config.include('deform_jinja2') config.add_static_view(name='static', path='weasyl:static') config.add_jinja2_search_path('weasyl:templates') config.add_view_predicate('api', predicates.APIPredicate) config.add_request_method(path_for) config.add_request_method(format_datetime) config.add_request_method(make_asset_path_finder()) config.add_request_method(current_user, reify=True) config.add_request_method(is_api_request, reify=True) config.add_request_method(is_debug_on, reify=True) config.add_request_method(login_forms, reify=True) config.add_tween( 'weasyl.sessions.session_tween_factory', under='pyramid_tm.tm_tween_factory') configure_urls(config) json_renderer = NoLeadingUnderscoresJSON() json_renderer.add_adapter(datetime.datetime, datetime_adapter) json_renderer.add_adapter(arrow.Arrow, datetime_adapter) config.add_renderer('json', json_renderer) auth_stack = AuthenticationStackPolicy(callback=authorization.groupfinder) auth_stack.add_policy( 'api_key', authentication.APIKeyAuthenticationPolicy(callback=authorization.groupfinder)) auth_stack.add_policy( 'session', SessionAuthenticationPolicy(prefix='', callback=authorization.groupfinder)) config.set_authentication_policy(auth_stack) config.set_authorization_policy(authorization.DelegatedAuthorizationPolicy()) config.scan('weasyl.views', ignore='weasyl.views.test') return config.make_wsgi_app()
from sqlalchemy.dialects.postgresql import psycopg2 from weasyl import config config._in_test = True # noqa from libweasyl.configuration import configure_libweasyl from libweasyl.models.tables import metadata from weasyl import cache, define, emailer, macro, media, middleware cache.region.configure('dogpile.cache.memory') define.metric = lambda *a, **kw: None configure_libweasyl( dbsession=define.sessionmaker, not_found_exception=HTTPNotFound, base_file_path='testing', staff_config_dict={}, media_link_formatter_callback=media.format_media_link, ) @pytest.fixture(scope='session', autouse=True) def setupdb(request): define.engine.execute('DROP SCHEMA public CASCADE') define.engine.execute('CREATE SCHEMA public') define.engine.execute('CREATE EXTENSION HSTORE') # hstore oids changed; de-memoize them and create new connections define.engine.dialect._hstore_oids = psycopg2.PGDialect_psycopg2._hstore_oids.__get__( define.engine.dialect) define.engine.dispose()
def weasyl_404(): userid = d.get_userid() return web.notfound( d.errorpage(userid, "**404!** The page you requested could not be found.")) app.notfound = weasyl_404 wsgi_app = app.wsgifunc() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'): from werkzeug.contrib.profiler import ProfilerMiddleware wsgi_app = ProfilerMiddleware(wsgi_app, profile_dir=m.MACRO_SYS_BASE_PATH + 'profile-stats') if d.config_obj.has_option('sentry', 'dsn'): wsgi_app = mw.SentryEnvironmentMiddleware( wsgi_app, d.config_obj.get('sentry', 'dsn')) configure_libweasyl( dbsession=d.sessionmaker, not_found_exception=web.notfound, base_file_path=m.MACRO_SYS_BASE_PATH, staff_config_path=m.MACRO_SYS_STAFF_CONFIG_PATH, media_link_formatter_callback=format_media_link, )
import pytest import web from weasyl import config config._in_test = True # noqa from libweasyl.configuration import configure_libweasyl from libweasyl.models.meta import registry from weasyl import cache, define, macro, media cache.region.configure('dogpile.cache.memory') define.metric = lambda *a, **kw: None configure_libweasyl( dbsession=define.sessionmaker, not_found_exception=web.notfound, base_file_path='testing', staff_config_path=macro.MACRO_SYS_STAFF_CONFIG_PATH, media_link_formatter_callback=media.format_media_link, ) @pytest.fixture(scope='session', autouse=True) def setupdb(request): db = define.connect() db.execute('DROP SCHEMA public CASCADE') db.execute('CREATE SCHEMA public') db.execute('CREATE EXTENSION HSTORE') define.meta.create_all(define.engine) @pytest.fixture(autouse=True)
config.add_request_method(mw.pg_connection_request_property, name='pg_connection', reify=True) config.add_request_method(mw.userid_request_property, name='userid', reify=True) config.add_request_method(mw.log_exc_request_method, name='log_exc') config.add_request_method(mw.web_input_request_method, name='web_input') config.add_request_method(mw.set_cookie_on_response) config.add_request_method(mw.delete_cookie_on_response) wsgi_app = config.make_wsgi_app() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'): from werkzeug.contrib.profiler import ProfilerMiddleware wsgi_app = ProfilerMiddleware(wsgi_app, profile_dir=m.MACRO_SYS_BASE_PATH + 'profile-stats') if d.config_obj.has_option('sentry', 'dsn'): wsgi_app = mw.SentryEnvironmentMiddleware( wsgi_app, d.config_obj.get('sentry', 'dsn')) configure_libweasyl( dbsession=d.sessionmaker, not_found_exception=HTTPNotFound, base_file_path=m.MACRO_SYS_BASE_PATH, staff_config_dict=read_staff_yaml.load_staff_dict(), media_link_formatter_callback=format_media_link, )
setup_routes_and_views(config) # Setup properties and methods for request objects. config.add_request_method(mw.pg_connection_request_property, name='pg_connection', reify=True) config.add_request_method(mw.userid_request_property, name='userid', reify=True) config.add_request_method(mw.log_exc_request_method, name='log_exc') config.add_request_method(mw.web_input_request_method, name='web_input') config.add_request_method(mw.set_cookie_on_response) config.add_request_method(mw.delete_cookie_on_response) wsgi_app = config.make_wsgi_app() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'): from werkzeug.contrib.profiler import ProfilerMiddleware wsgi_app = ProfilerMiddleware( wsgi_app, profile_dir=m.MACRO_STORAGE_ROOT + 'profile-stats') if d.config_obj.has_option('sentry', 'dsn'): wsgi_app = mw.SentryEnvironmentMiddleware(wsgi_app, d.config_obj.get('sentry', 'dsn')) configure_libweasyl( dbsession=d.sessionmaker, not_found_exception=HTTPNotFound, base_file_path=m.MACRO_STORAGE_ROOT, staff_config_dict=staff_config.load(), media_link_formatter_callback=format_media_link, )