How to use the connexion.utils.get_function_from_name function in connexion

To help you get started, we’ve selected a few connexion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalando / connexion / tests / test_utils.py View on Github external
def test_get_function_from_name_attr_error(monkeypatch):
    """
    Test attribute error without import error on get_function_from_name.
    Attribute errors due to import errors are tested on
    test_api.test_invalid_operation_does_stop_application_to_setup
    """
    deep_attr_mock = MagicMock()
    deep_attr_mock.side_effect = AttributeError
    monkeypatch.setattr("connexion.utils.deep_getattr", deep_attr_mock)
    with pytest.raises(AttributeError):
        utils.get_function_from_name('math.ceil')
github zalando / connexion / tests / test_utils.py View on Github external
def test_get_function_from_name_no_module():
    with pytest.raises(ValueError):
        utils.get_function_from_name('math')
github common-workflow-language / workflow-service / wes_service / wes_service_main.py View on Github external
args = argparse.Namespace()

    configfile = "config.yml"
    if os.path.isfile(configfile):
        logging.info("Loading %s", configfile)
        with open(configfile, "r") as f:
            config = ruamel.yaml.safe_load(f)
        for c in config:
            setattr(args, c, config[c])

    logging.info("Using config:")
    for n in args.__dict__:
        logging.info("  %s: %s", n, getattr(args, n))

    app = connexion.App(__name__)
    backend = utils.get_function_from_name(args.backend + ".create_backend")(
        app, args.opt
    )

    def rs(x):
        return getattr(backend, x.split(".")[-1])

    app.add_api(
        "openapi/workflow_execution_service.swagger.yaml", resolver=Resolver(rs)
    )

    return app
github zalando / connexion / connexion / cli.py View on Github external
spec_file_full_path = path.abspath(spec_file)
    py_module_path = base_module_path or path.dirname(spec_file_full_path)
    sys.path.insert(1, path.abspath(py_module_path))
    logger.debug('Added {} to system path.'.format(py_module_path))

    resolver_error = None
    if stub:
        resolver_error = 501

    api_extra_args = {}
    if mock:
        resolver = MockResolver(mock_all=mock == 'all')
        api_extra_args['resolver'] = resolver

    app_cls = connexion.utils.get_function_from_name(
      AVAILABLE_APPS[app_framework]
    )

    options = {
        "serve_spec": not hide_spec,
        "swagger_path": console_ui_from or None,
        "swagger_ui": not hide_console_ui,
        "swagger_url": console_ui_url or None
    }

    app = app_cls(__name__,
                  debug=debug,
                  auth_all_paths=auth_all_paths,
                  options=options)

    app.add_api(spec_file_full_path,
github common-workflow-language / workflow-service / wes_service / __init__.py View on Github external
configfile = "config.yml"
    if os.path.isfile(configfile):
        logging.info("Loading %s", configfile)
        with open(configfile, "r") as f:
            config = ruamel.yaml.safe_load(f)
        for c in config:
            setattr(args, c, config[c])


    logging.info("Using config:")
    for n in args.__dict__:
        logging.info("  %s: %s", n, getattr(args, n))

    app = connexion.App(__name__)
    backend = utils.get_function_from_name(
        args.backend + ".create_backend")(args.opt)

    def rs(x):
        return getattr(backend, x)

    app.add_api(
        'openapi/workflow_execution_service.swagger.yaml',
        resolver=Resolver(rs))

    return app
github zalando / connexion / connexion / decorators / security.py View on Github external
def get_scope_validate_func(security_definition):
    """
    :type security_definition: dict
    :rtype: function

    >>> get_scope_validate_func({'x-scopeValidateFunc': 'foo.bar'})
    ''
    """
    func = (security_definition.get("x-scopeValidateFunc") or
            os.environ.get('SCOPEVALIDATE_FUNC'))
    if func:
        return get_function_from_name(func)
    return validate_scope