How to use connexion - 10 common examples

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 anchore / anchore-engine / legacy_test / services / test_api_specs.py View on Github external
Creates a mocked interface for each specified swagger spec and runs a server with a forked process to ensure swagger validates fully.

        :return:
        """

        port = 8088
        for swagger in self.service_swaggers:
            swagger = os.path.join(self.prefix, swagger)
            pid = os.fork()
            if not pid:
                name = swagger.split('/')[2]
                print(('Starting server for: {} at: {}'.format(name, swagger)))
                resolver = MockResolver(mock_all='all')
                api_extra_args ={'resolver': resolver}

                app = connexion.FlaskApp(name,
                                         swagger_json=False,
                                         swagger_ui=False)

                app.add_api(swagger + '/swagger.yaml',
                            resolver_error=True,
                            validate_responses=True,
                            strict_validation=True,
                            **api_extra_args)

                app.run(port=port)

            else:
                try:
                    print('Wait for pinging server')
                    # Let the api initialize
                    time.sleep(2)
github ga4gh / cloud-interop-testing / ga4ghtest / controllers / servers_controller.py View on Github external
def register_server(
    body
):  # noqa: E501
    """Register a server

    Add an API server to the testbed. # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: str
    """
    if connexion.request.is_json:
        body = Server.from_dict(connexion.request.get_json())  # noqa: E501
    return controller.register_server(
        body=body
    )
github zalando / connexion / tests / test_cli.py View on Github external
def mock_app_run(mock_get_function_from_name):
    test_server = MagicMock(wraps=connexion.FlaskApp(__name__))
    test_server.run = MagicMock(return_value=True)
    test_app = MagicMock(return_value=test_server)
    mock_get_function_from_name.return_value = test_app
    return test_app
github Remmeauth / remme-core / tests / test_rest_api.py View on Github external
def setUpClass(cls):
        super().setUpClass(AccountHandler, AccountClient)
        flask_app = connexion.FlaskApp('remme.rest_api')
        flask_app.add_api(resource_filename('remme.rest_api', 'openapi.yml'),
                          resolver=RestMethodsSwitcherResolver('remme.rest_api'))
        cls.client = flask_app.app.test_client()
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_no_swagger_ui(aiohttp_api_spec_dir, aiohttp_client):
    options = {"swagger_ui": False}
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     options=options, debug=True)
    app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_ui = yield from app_client.get('/v1.0/ui/')
    assert swagger_ui.status == 404

    app2 = AioHttpApp(__name__, port=5001,
                      specification_dir=aiohttp_api_spec_dir,
                      debug=True)
    options = {"swagger_ui": False}
    app2.add_api('swagger_simple.yaml', options=options)
    app2_client = yield from aiohttp_client(app.app)
    swagger_ui2 = yield from app2_client.get('/v1.0/ui/')
    assert swagger_ui2.status == 404
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_swagger_ui_static(aiohttp_api_spec_dir, aiohttp_client):
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     debug=True)
    app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_ui = yield from app_client.get('/v1.0/ui/lib/swagger-oauth.js')
    assert swagger_ui.status == 200

    app_client = yield from aiohttp_client(app.app)
    swagger_ui = yield from app_client.get('/v1.0/ui/swagger-ui.min.js')
    assert swagger_ui.status == 200
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_no_swagger_json(aiohttp_api_spec_dir, aiohttp_client):
    """ Verify the swagger.json file is not returned when set to False when creating app. """
    options = {"swagger_json": False}
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     options=options,
                     debug=True)
    app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_json = yield from app_client.get('/v1.0/swagger.json')  # type: flask.Response
    assert swagger_json.status == 404
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_swagger_json(aiohttp_api_spec_dir, aiohttp_client):
    """ Verify the swagger.json file is returned for default setting passed to app. """
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     debug=True)
    api = app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_json = yield from app_client.get('/v1.0/swagger.json')

    assert swagger_json.status == 200
    json_ = yield from swagger_json.json()
    assert api.specification.raw == json_
github zalando / connexion / tests / aiohttp / test_aiohttp_app.py View on Github external
def test_app_add_two_apis_error_with_only_one_api(aiohttp_api_spec_dir):
    spec_dir = '..' / aiohttp_api_spec_dir.relative_to(TEST_FOLDER)
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=spec_dir,
                     debug=True,
                     only_one_api=True)
    app.add_api('swagger_empty_base_path.yaml')

    with pytest.raises(ConnexionException) as exc_info:
        app.add_api('swagger_empty_base_path.yaml')

    assert exc_info.value.args == (
        "an api was already added, "
        "create a new app with 'only_one_api=False' "
github zalando / connexion / tests / aiohttp / test_aiohttp_app.py View on Github external
def test_app_get_root_path_not_in_sys_modules(sys_modules_mock, aiohttp_api_spec_dir):
    app = AioHttpApp('connexion', port=5001,
                     specification_dir=aiohttp_api_spec_dir)
    assert app.get_root_path().endswith(os.sep + 'connexion') == True