Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'connexion' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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)
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
)
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
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()
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
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
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
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_
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' "
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