예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
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
예제 #4
0
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()
예제 #5
0
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()
예제 #6
0
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()
예제 #7
0
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))
예제 #8
0
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
예제 #9
0
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)
예제 #10
0
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()
예제 #11
0
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
예제 #12
0
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
예제 #13
0
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()
예제 #14
0
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
예제 #15
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()
예제 #16
0
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
예제 #17
0
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
예제 #18
0
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()
예제 #19
0
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
예제 #20
0
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
예제 #21
0
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
예제 #22
0
 def make_app(self, settings):
     loop = self.get_loop()
     return make_app(settings=settings, loop=loop)
예제 #23
0
 def make_app(self, settings):
     return make_app(settings=settings)
예제 #24
0
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"]})
예제 #25
0
 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))
예제 #26
0
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))
예제 #27
0
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)
예제 #28
0
 def make_app(self, settings):
     signal.signal(signal.SIGINT, self.signal_handler)
     return make_app(settings=settings, loop=self.get_loop())
예제 #29
0
 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))
예제 #30
0
# -*- 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')