def setup_app(): settings = TESTING_SETTINGS.copy() settings['applications'] = ['guillotina.documentation'] aioapp = make_app(settings=settings) @configure.addon( name="myaddon", title="My addon") class MyAddon(Addon): @classmethod def install(cls, site, request): # install code pass @classmethod def uninstall(cls, site, request): # uninstall code pass config = aioapp.config configure.load_configuration( config, 'guillotina.documentation', 'addon') aioapp.config.execute_actions() load_cached_schema()
async def dummy_guillotina(event_loop, request): globalregistry.reset() app = make_app(settings=get_dummy_settings(request.node), loop=event_loop) async with TestClient(app): yield app logout() clear_task_vars()
def guillotina_main(loop): HARD_CACHE.clear() from guillotina import test_package # noqa aioapp = make_app(settings=PG_SETTINGS, loop=loop) aioapp.config.execute_actions() load_cached_schema() yield aioapp
async def app(event_loop, db, request): globalregistry.reset() settings = get_db_settings(request.node) app = make_app(settings=settings, loop=event_loop) server_settings = settings.get("test_server_settings", {}) host = server_settings.get("host", "127.0.0.1") port = int(server_settings.get("port", 8000)) from uvicorn import Config, Server config = Config(app, host=host, port=port, lifespan="on") server = Server(config=config) task = asyncio.ensure_future(server.serve(), loop=event_loop) while app.app is None and not task.done(): # Wait for app initialization await asyncio.sleep(0.05) if task.done(): task.result() await _clear_dbs(app.app.root) yield host, port server.should_exit = True await asyncio.sleep(1) # There is no other way to wait for server shutdown clear_task_vars()
def dummy_guillotina(loop): from guillotina import test_package # noqa aioapp = make_app(settings=get_dummy_settings(), loop=loop) aioapp.config.execute_actions() load_cached_schema() yield aioapp close_async_tasks()
async def app_client(event_loop, db, request): globalregistry.reset() app = make_app(settings=get_db_settings(request.node), loop=event_loop) async with TestClient(app, timeout=30) as client: await _clear_dbs(app.app.root) yield app, client clear_task_vars()
def guillotina_main(loop): HARD_CACHE.clear() aioapp = make_app(settings=get_pg_settings(), loop=loop) aioapp.config.execute_actions() load_cached_schema() yield aioapp loop.run_until_complete(close_async_tasks(aioapp))
def get_server(): global _server if _server is not None: return _server loop = asyncio.get_event_loop() aioapp = make_app( settings={ "applications": ["guillotina.documentation"], "databases": { "db": { "storage": "DUMMY", "dsn": {}, "name": "db" } }, "root_user": { "password": "******" }, "jwt": { "secret": "foobar", "algorithm": "HS256" }, }, loop=loop, ) load_cached_schema() client = loop.run_until_complete(TestClient(aioapp).__aenter__()) _server = {"loop": loop, "client": client, "app": aioapp} return _server
def run_guillotina(settings): web_loop = asyncio.new_event_loop() app = make_app(settings=settings, loop=web_loop) asyncio.set_event_loop(web_loop) web.run_app(app, host=settings.get('host', '0.0.0.0'), port=settings.get('address', settings.get('port')), loop=web_loop)
def guillotina_main(loop): HARD_CACHE.clear() from guillotina import test_package # noqa aioapp = make_app(settings=get_pg_settings(), loop=loop) aioapp.config.execute_actions() load_cached_schema() yield aioapp close_async_tasks()
def guillotina_main(loop): globalregistry.reset() aioapp = make_app(settings=get_db_settings(), loop=loop) aioapp.config.execute_actions() load_cached_schema() yield aioapp try: loop.run_until_complete(close_async_tasks(aioapp)) except asyncio.CancelledError: pass
def dummy_guillotina(loop): globalregistry.reset() aioapp = loop.run_until_complete( make_app(settings=get_dummy_settings(), loop=loop)) aioapp.config.execute_actions() load_cached_schema() yield aioapp try: loop.run_until_complete(close_async_tasks(aioapp)) except asyncio.CancelledError: pass
def dummy_guillotina(loop, request): globalregistry.reset() aioapp = loop.run_until_complete( make_app(settings=get_dummy_settings(request.node), loop=loop)) aioapp.config.execute_actions() load_cached_schema() yield aioapp try: loop.run_until_complete(close_async_tasks(aioapp)) except asyncio.CancelledError: pass logout()
def test_not_warn_about_jwt_secret(loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ "debug": True, "jwt": { "algorithm": "HS256", "secret": "secret" } }) with caplog.at_level(logging.WARNING, logger="guillotina"): globalregistry.reset() loop.run_until_complete(make_app(settings=settings, loop=loop)) assert len(caplog.records) == 0
def guillotina_in_thread(port): # Create a new loop and set it loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) # Create guillotina app globalregistry.reset() aioapp = loop.run_until_complete( make_app(settings=get_db_settings(), loop=loop)) aioapp.config.execute_actions() load_cached_schema() # Create test server with app server = TestServer(aioapp, loop=loop, port=port) loop.run_until_complete(server.start_server(loop=loop)) loop.run_forever()
def test_warn_about_jwt_complexity(loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ "debug": False, "jwt": { "algorithm": "HS256", "secret": "DKK@7328*!&@@" } }) with caplog.at_level(logging.WARNING, logger="guillotina"): globalregistry.reset() loop.run_until_complete(make_app(settings=settings, loop=loop)) assert len(caplog.records) == 1 assert "insecure secret" in caplog.records[0].message
def test_warn_about_jwt_secret(loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ 'debug': False, 'jwt': { "algorithm": "HS256", 'secret': 'secret' } }) with caplog.at_level(logging.WARNING, logger='guillotina'): globalregistry.reset() loop.run_until_complete(make_app(settings=settings, loop=loop)) assert len(caplog.records) == 1 assert 'strongly advised' in caplog.records[0].message
async def test_not_warn_about_jwt_secret(event_loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ "debug": True, "jwt": { "algorithm": "HS256", "secret": "secret" } }) with caplog.at_level(logging.WARNING, logger="guillotina"): globalregistry.reset() app = make_app(settings=settings, loop=event_loop) await app.startup() assert len(caplog.records) == 0 await app.shutdown()
def get_server(): global _server if _server is not None: return _server loop = asyncio.new_event_loop() aioapp = loop.run_until_complete( make_app( settings={ "applications": ["guillotina.documentation"], "databases": { "db": { "storage": "DUMMY", "dsn": {}, "name": "db" } }, "root_user": { "password": "******" }, "jwt": { "secret": "foobar", "algorithm": "HS256" }, }, loop=loop, )) aioapp.config.execute_actions() load_cached_schema() server = TestServer(aioapp) loop.run_until_complete(server.start_server(loop=loop)) _server = { "loop": loop, "server": server, "client": TestClient(server, loop=loop), "app": aioapp } return _server
def get_server(): global _server if _server is not None: return _server loop = asyncio.new_event_loop() aioapp = loop.run_until_complete(make_app( settings={ "applications": ["guillotina.documentation"], "databases": { "db": { "storage": "DUMMY", "dsn": {}, "name": "db" } }, "root_user": { "password": "******" }, "jwt": { "secret": "foobar", "algorithm": "HS256" }, }, loop=loop)) aioapp.config.execute_actions() load_cached_schema() server = TestServer(aioapp) loop.run_until_complete(server.start_server(loop=loop)) _server = { 'loop': loop, 'server': server, 'client': TestClient(server, loop=loop), 'app': aioapp } return _server
def dummy_guillotina(loop): from guillotina import test_package # noqa aioapp = make_app(settings=DUMMY_SETTINGS, loop=loop) aioapp.config.execute_actions() load_cached_schema() return aioapp
def make_app(self, settings): loop = self.get_loop() return make_app(settings=settings, loop=loop)
def make_app(self, settings): return make_app(settings=settings)
from guillotina.response import Response @configure.service(method="GET", context=IApplication, permission="guillotina.Public") async def index(context, request): return Response(body=b"") @configure.service( method="GET", context=IApplication, permission="guillotina.Public", name="/user/{id}", ) async def user_info(context, request): id_ = request.matchdict["id"] return Response(body=id_.encode("utf-8")) @configure.service(method="POST", context=IApplication, permission="guillotina.Public", name="/user") async def user_info(context, request): return Response(body=b"") app = make_app(settings={"applications": ["server"]})
def make_app(self, settings): signal.signal(signal.SIGINT, self.signal_handler) loop = self.get_loop() return loop.run_until_complete( make_app(settings=settings, loop=loop))
def dummy_guillotina(loop): aioapp = make_app(settings=get_dummy_settings(), loop=loop) aioapp.config.execute_actions() load_cached_schema() yield aioapp loop.run_until_complete(close_async_tasks(aioapp))
from guillotina.factory import make_app import os if "G_CONFIG_FILE" not in os.environ: raise Exception("You must provide the envar G_CONFIG_FILE") config_file = os.environ["G_CONFIG_FILE"] app = make_app(config_file=config_file)
def make_app(self, settings): signal.signal(signal.SIGINT, self.signal_handler) return make_app(settings=settings, loop=self.get_loop())
def make_app(self, settings): signal.signal(signal.SIGINT, self.signal_handler) loop = self.get_loop() return loop.run_until_complete(make_app(settings=settings, loop=loop))
# -*- coding: utf-8 -*- from guillotina.factory import make_app import logging logging.basicConfig( level=logging.DEBUG, format='%(threadName)10s %(name)18s: %(message)s', ) app = make_app(config_file='config.json')