def __init__(self, *args, **kwargs): ''' initialize the test class ''' TestCase.__init__(self, *args, **kwargs) LOG.debug("ConfigFile: %s " % config['__file__']) conffile = config['__file__'] if pylons.test.pylonsapp: wsgiapp = pylons.test.pylonsapp else: wsgiapp = loadapp('config: %s' % config['__file__']) self.app = TestApp(wsgiapp) conf = None if conffile.startswith('/'): conf = appconfig('config:%s' % config['__file__'], relative_to=None) else: raise Exception('dont know how to load the application relatively') #conf = appconfig('config: %s' % config['__file__'], relative_to=rel) load_environment(conf.global_conf, conf.local_conf) self.appconf = conf url._push_object(URLGenerator(config['routes.map'], environ)) self.isSelfTest = False if env.has_key("linotp.selfTest"): self.isSelfTest = True return
def setup_app(command, conf, param): ''' setup_app is the hook, which is called, when the application is created :param command: - not used - :param conf: the application configuration :param vars: - not used - :return: - nothing - ''' # from http://pylons-webframework.readthedocs.org/en/latest/upgrading.html # Add under the 'def setup_app': # Don't reload the app if it was loaded under the testing environment if not pylons.test.pylonsapp: load_environment(conf.global_conf, conf.local_conf) unitTest = conf.has_key('unitTest') import linotp.lib.base linotp.lib.base.setup_app(conf.local_conf, conf.global_conf, unitTest) if alembicconfig_available and alembic_available: upgrade_databases(conf.local_conf, conf.global_conf) return
def __init__(self, *args, **kwargs): ''' initialize the test class ''' TestCase.__init__(self, *args, **kwargs) LOG.error("ConfigFile: %s " % config['__file__']) conffile = config['__file__'] if pylons.test.pylonsapp: wsgiapp = pylons.test.pylonsapp else: wsgiapp = loadapp('config: %s' % config['__file__']) self.app = TestApp(wsgiapp) conf = None if conffile.startswith('/'): conf = appconfig('config:%s' % config['__file__'], relative_to=None) else: raise Exception('dont know how to load the application relatively') #conf = appconfig('config: %s' % config['__file__'], relative_to=rel) load_environment(conf.global_conf, conf.local_conf) self.appconf = conf url._push_object(URLGenerator(config['routes.map'], environ)) self.isSelfTest = False if env.has_key("linotp.selfTest"): self.isSelfTest = True return
def setup_app(command, conf, param): ''' setup_app is the hook, which is called, when the application is created :param command: - not used - :param conf: the application configuration :param vars: - not used - :return: - nothing - ''' load_environment(conf.global_conf, conf.local_conf) unitTest = conf.has_key('unitTest') linotp.lib.base.setup_app(conf.local_conf, conf.global_conf, unitTest)
def setup_app(command, conf, param): ''' setup_app is the hook, which is called, when the application is created :param command: - not used - :param conf: the application configuration :param vars: - not used - :return: - nothing - ''' load_environment(conf.global_conf, conf.local_conf) unitTest = conf.has_key('unitTest') import linotp.lib.base linotp.lib.base.setup_app(conf.local_conf, conf.global_conf, unitTest)
def setup_app(command, conf, param): ''' setup_app is the hook, which is called, when the application is created :param command: - not used - :param conf: the application configuration :param vars: - not used - :return: - nothing - ''' load_environment(conf.global_conf, conf.local_conf) unitTest = conf.has_key('unitTest') import linotp.lib.base linotp.lib.base.setup_app(conf.local_conf, conf.global_conf, unitTest) if alembicconfig_available and alembic_available: upgrade_databases(conf.local_conf, conf.global_conf) return
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) g = config['pylons.app_globals'] g.cache_manager = app.cache_manager # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # this is a compatibility hack for pylons > 1.0!!! conf = PyConf(config) conf['global_conf'] = global_conf conf['app_conf'] = app_conf conf['__file__'] = global_conf['__file__'] conf['FILE'] = global_conf['__file__'] conf['routes.map'] = config['routes.map'] if not hasattr(conf, 'init_app'): setattr(conf, 'init_app', config.init_app) app.config = conf return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Profiling Middleware if profile_load: if asbool(config['profile']): app = AccumulatingProfileMiddleware( app, log_filename='/var/log/linotp/profiling.log', cachegrind_filename='/var/log/linotp/cachegrind.out', discard_first_request=True, flush_at_shutdown=True, path='/__profile__') # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # repoze.who if repoze_load: if 'who.generate_random_secret' in app_conf and not app_conf[ 'who.generate_random_secret']: app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level']) else: # Read the current configuration file and replace "secret" keys in every line who_config_lines = [] secret = binascii.hexlify(os.urandom(16)) if len(secret) != 32: raise RuntimeError( 'Could not generate random repoze.who secret, no os.urandom support?' ) with open(app_conf['who.config_file']) as f: for line in f.readlines(): who_config_lines.append( re.sub(r'^(secret)\s*=\s*.*$', r'\1 = %s' % secret, line)) with tempinput(''.join(who_config_lines)) as who_config_file: app = make_who_with_config(app, global_conf, who_config_file, app_conf['who.log_file'], app_conf['who.log_level']) # this is a compatibility hack for pylons > 1.0!!! conf = PyConf(config) conf['global_conf'] = global_conf conf['app_conf'] = app_conf conf['__file__'] = global_conf['__file__'] conf['FILE'] = global_conf['__file__'] conf['routes.map'] = config['routes.map'] if not hasattr(conf, 'init_app'): setattr(conf, 'init_app', config.init_app) app.config = conf return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Profiling Middleware if profile_load: if asbool(config['profile']): app = AccumulatingProfileMiddleware( app, log_filename='/var/log/linotp/profiling.log', cachegrind_filename='/var/log/linotp/cachegrind.out', discard_first_request=True, flush_at_shutdown=True, path='/__profile__' ) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # repoze.who if repoze_load: if 'who.generate_random_secret' in app_conf and not app_conf['who.generate_random_secret']: app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level']) else: # Read the current configuration file and replace "secret" keys in every line who_config_lines = [] secret = binascii.hexlify(os.urandom(16)) if len(secret) != 32: raise RuntimeError('Could not generate random repoze.who secret, no os.urandom support?') with open(app_conf['who.config_file']) as f: for line in f.readlines(): who_config_lines.append(re.sub(r'^(secret)\s*=\s*.*$', r'\1 = %s' % secret, line)) with tempinput(''.join(who_config_lines)) as who_config_file: app = make_who_with_config(app, global_conf, who_config_file, app_conf['who.log_file'], app_conf['who.log_level']) # this is a compatibility hack for pylons > 1.0!!! conf = PyConf(config) conf['global_conf'] = global_conf conf['app_conf'] = app_conf conf['__file__'] = global_conf['__file__'] conf['FILE'] = global_conf['__file__'] conf['routes.map'] = config['routes.map'] if not hasattr(conf, 'init_app'): setattr(conf, 'init_app', config.init_app) app.config = conf return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Profiling Middleware if profile_load: if asbool(config['profile']): app = AccumulatingProfileMiddleware( app, log_filename='/var/log/linotp/profiling.log', cachegrind_filename='/var/log/linotp/cachegrind.out', discard_first_request=True, flush_at_shutdown=True, path='/__profile__' ) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # repoze.who if repoze_load: app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level']) return app