Exemplo n.º 1
0
def web_server(
    loop,
    app_cfg: Dict,
    monkeypatch,
    postgres_db,
    aiohttp_server,
    disable_static_webserver,
) -> TestServer:
    print(
        "Inits webserver with app_cfg",
        json.dumps(app_cfg, indent=2, cls=_BaseSettingEncoder),
    )

    # original APP
    app = create_application(app_cfg)

    assert app[APP_CONFIG_KEY] == app_cfg

    # with patched email
    _path_mail(monkeypatch)

    disable_static_webserver(app)

    server = loop.run_until_complete(
        aiohttp_server(app, port=app_cfg["main"]["port"]))

    assert isinstance(postgres_db, sa.engine.Engine)
    pg_settings = dict(
        e.split("=") for e in app[APP_DB_ENGINE_KEY].dsn.split())
    assert pg_settings["host"] == postgres_db.url.host
    assert int(pg_settings["port"]) == postgres_db.url.port
    assert pg_settings["user"] == postgres_db.url.username

    return server
Exemplo n.º 2
0
def client(
    loop,
    aiohttp_client,
    app_cfg,
    monkeypatch,
    postgres_db,
    mock_orphaned_services,
    disable_static_webserver,
    monkeypatch_setenv_from_app_config: Callable,
):
    extra_test_routes = web.RouteTableDef()

    @extra_test_routes.get("/session")
    async def _return_session(request: web.Request):
        session = await get_aiohttp_session(request)
        return web.json_response(dict(session))

    monkeypatch_setenv_from_app_config(app_cfg)
    app = create_application()

    app.add_routes(extra_test_routes)

    return loop.run_until_complete(
        aiohttp_client(
            app,
            server_kwargs={
                "port": app_cfg["main"]["port"],
                "host": app_cfg["main"]["host"],
            },
        )
    )
Exemplo n.º 3
0
def web_server(
    loop,
    app_cfg: ConfigDict,
    monkeypatch: MonkeyPatch,
    postgres_db,
    aiohttp_server: Callable,
    disable_static_webserver: Callable,
    monkeypatch_setenv_from_app_config: Callable,
) -> TestServer:

    print("+ web_server:")
    cfg = deepcopy(app_cfg)
    monkeypatch_setenv_from_app_config(cfg)

    # original APP
    app = create_application()

    # with patched email
    _path_mail(monkeypatch)

    disable_static_webserver(app)

    server = loop.run_until_complete(aiohttp_server(app, port=cfg["main"]["port"]))

    assert isinstance(postgres_db, sa.engine.Engine)
    pg_settings = dict(e.split("=") for e in app[APP_DB_ENGINE_KEY].dsn.split())
    assert pg_settings["host"] == postgres_db.url.host
    assert int(pg_settings["port"]) == postgres_db.url.port
    assert pg_settings["user"] == postgres_db.url.username

    return server
Exemplo n.º 4
0
def server(loop, aiohttp_server, app_cfg, monkeypatch, aiohttp_unused_port,
           postgres_db):  #pylint: disable=R0913
    port = app_cfg["main"]["port"] = aiohttp_unused_port()

    app = create_application(app_cfg)
    path_mail(monkeypatch)
    server = loop.run_until_complete(aiohttp_server(app, port=port))
    return server
Exemplo n.º 5
0
def web_server(loop, aiohttp_server, app_cfg, monkeypatch, postgres_db):
    # original APP
    app = create_application(app_cfg)

    # with patched email
    path_mail(monkeypatch)

    server = loop.run_until_complete(
        aiohttp_server(app, port=app_cfg["main"]["port"]))
    return server
Exemplo n.º 6
0
def web_server(loop, aiohttp_server, app_cfg, monkeypatch, postgres_db):
    # original APP
    app = create_application(app_cfg)

    from servicelib.application_keys import APP_CONFIG_KEY
    import json
    print("Inits webserver with config", json.dumps(app[APP_CONFIG_KEY], indent=2))

    # with patched email
    _path_mail(monkeypatch)

    server = loop.run_until_complete(aiohttp_server(app, port=app_cfg["main"]["port"]))
    return server
def client(loop, aiohttp_client, app_cfg, postgres_service):

    # config app
    cfg = deepcopy(app_cfg)
    port = cfg["main"]["port"]
    cfg["db"]["init_tables"] = True  # inits tables of postgres_service upon startup
    cfg["projects"]["enabled"] = True

    app = application.create_application(cfg)

    # server and client
    return loop.run_until_complete(
        aiohttp_client(app, server_kwargs={"port": port, "host": "localhost"})
    )
Exemplo n.º 8
0
def client(event_loop, aiohttp_client, app_cfg, postgres_db):

    # config app
    cfg = deepcopy(app_cfg)
    port = cfg["main"]["port"]
    cfg["projects"]["enabled"] = True

    app = application.create_application()

    # server and client
    return event_loop.run_until_complete(
        aiohttp_client(app, server_kwargs={
            "port": port,
            "host": "localhost"
        }))
Exemplo n.º 9
0
def web_server(loop, aiohttp_server, app_cfg: Dict, monkeypatch,
               postgres_db) -> TestServer:
    print(
        "Inits webserver with app_cfg",
        json.dumps(app_cfg, indent=2, cls=_BaseSettingEncoder),
    )
    # original APP
    app = create_application(app_cfg)

    assert app[APP_CONFIG_KEY] == app_cfg

    # with patched email
    _path_mail(monkeypatch)

    server = loop.run_until_complete(
        aiohttp_server(app, port=app_cfg["main"]["port"]))
    return server