Ejemplo n.º 1
0
def test_filter_app(fakeapp):
    # Specifically the 'filter-app' config type
    config_path = os.path.join(here, 'config_files/filter_app.ini')
    app = load_app(config_path)
    assert app.method_to_call == 'lower'
    assert app.app.method_to_call == 'upper'
    assert app.app.app is fakeapp.apps.basic_app
def test_filter_app():
    # Specifically the 'filter-app' config type
    config_path = os.path.join(here, 'config_files/filter_app.ini')
    app = load_app(config_path)
    assert app.method_to_call == 'lower'
    assert app.app.method_to_call == 'upper'
    assert app.app.app is montague_testapps.apps.basic_app
Ejemplo n.º 3
0
def safe_load_app(config_file, name='main'):
    try:
        return load_app(config_file, name)
    except KeyError as e:
        key_missing = e.args[0]
        msg = 'Missing Key in section application#%s: %s' % (name, key_missing)
        click.echo(msg)
        sys.exit(1)
Ejemplo n.º 4
0
def safe_load_app(config_file, name='main'):
    try:
        return load_app(config_file, name)
    except KeyError as e:
        key_missing = e.args[0]
        msg = 'Missing Key in section application#%s: %s' % (
            name,
            key_missing
        )
        click.echo(msg)
        sys.exit(1)
Ejemplo n.º 5
0
    def get_routes(self,
                   config_file,
                   path_blacklist=None,
                   path_whitelist=None,
                   module_blacklist=None,
                   module_whitelist=None):

        app = load_app(config_file)
        env = prepare()
        registry = env['registry']
        config = Configurator(registry=registry)
        mapper = config.get_routes_mapper()

        try:  # only supported in pyramid 1.6
            routes = mapper.get_routes(include_static=True)
        except:
            routes = mapper.get_routes()

        mapped_routes = []

        for route in routes:
            route_data = get_route_data(route, registry)
            for name, pattern, view, method, docs, src in route_data:
                if path_blacklist:
                    if self.matches_pattern(path_blacklist, pattern):
                        continue

                if path_whitelist:
                    if not self.matches_pattern(path_whitelist, pattern):
                        continue

                if module_blacklist:
                    if self.matches_pattern(module_blacklist, view):
                        continue

                if module_whitelist:
                    if not self.matches_pattern(module_whitelist, view):
                        continue

                mapped_routes.append({
                    'name': name,
                    'pattern': pattern,
                    'view': view,
                    'method': method,
                    'docs': trim(docs),
                    'view_module': src.get('module_name'),
                    'view_callable': src.get('callable_name'),
                    'source_lines': src.get('source_lines'),
                })

        return mapped_routes
Ejemplo n.º 6
0
 def __init__(self, config_file, app_env, server_env):
     self.config_file = config_file
     self.app_env = app_env
     self.server_env = server_env
     self.app = load_app(config_file, name=app_env)
     self.pyramid_env = prepare()
Ejemplo n.º 7
0
 def loadapp(self, app_spec, name, relative_to, **kw): # pragma: no cover
     if app_spec.startswith('config:'):
         app_spec = app_spec[len('config:'):]
     path = os.path.join(relative_to, app_spec)
     return load_app(path, name)
Ejemplo n.º 8
0
def test_load_app():
    config_path = os.path.join(here, 'config.toml')
    app = load_app(config_path)
    app2 = load_app(config_path, name='egg')
    assert app is montague_testapps.apps.basic_app
    assert app2 is montague_testapps.apps.basic_app2
Ejemplo n.º 9
0
def test_load_filtered_app(fakeapp):
    config_path = os.path.join(here, 'config_files/simple_config.ini')
    app = load_app(config_path, name='filtered-app')
    assert isinstance(app, fakeapp.apps.CapFilter)
    assert app.app is fakeapp.apps.basic_app
    assert app.method_to_call == 'lower'
Ejemplo n.º 10
0
def test_load_app(fakeapp):
    config_path = os.path.join(here, 'config_files/simple_config.ini')
    app = load_app(config_path)
    app2 = load_app(config_path, name='egg')
    assert app is fakeapp.apps.basic_app
    assert app2 is fakeapp.apps.basic_app2
def test_load_filtered_app():
    config_path = os.path.join(here, 'config_files/simple_config.ini')
    app = load_app(config_path, name='filtered-app')
    assert isinstance(app, montague_testapps.apps.CapFilter)
    assert app.app is montague_testapps.apps.basic_app
    assert app.method_to_call == 'lower'
def test_load_app():
    config_path = os.path.join(here, 'config_files/simple_config.ini')
    app = load_app(config_path)
    assert app is montague_testapps.apps.basic_app
Ejemplo n.º 13
0
 def __init__(self, config_file, app_env, server_env):
     self.config_file = config_file
     self.app_env = app_env
     self.server_env = server_env
     self.app = load_app(config_file, name=app_env)
     self.pyramid_env = prepare()
Ejemplo n.º 14
0
def test_load_filtered_app(working_set):
    config_path = os.path.join(here, 'config_files/simple_config.json')
    app = load_app(config_path, name='filtered-app')
    assert isinstance(app, montague_testapps.apps.CapFilter)
    assert app.app is montague_testapps.apps.basic_app
    assert app.method_to_call == 'lower'
Ejemplo n.º 15
0
def test_load_app(working_set):
    config_path = os.path.join(here, 'config_files/simple_config.json')
    app = load_app(config_path)
    app2 = load_app(config_path, name='egg')
    assert app is montague_testapps.apps.basic_app
    assert app2 is montague_testapps.apps.basic_app2