Exemple #1
0
def _create_routes(tag, specs, *handlers_module, disable_login: bool = False):
    """
    :param disable_login: Disables login_required decorator for testing purposes defaults to False
    :type disable_login: bool, optional
    """
    # TODO: Remove 'disable_login' and use instead a mock.patch on the decorator!

    handlers = {}
    for mod in handlers_module:
        handlers.update(get_handlers_from_namespace(mod))

    if disable_login:
        handlers = {name: hnds.__wrapped__ for name, hnds in handlers.items()}

    routes = map_handlers_with_operations(
        handlers,
        filter(
            lambda o: tag in o[3] and "snapshot" not in o[2],
            iter_path_operations(specs),
        ),
        strict=True,
    )

    if disable_login:
        logger.debug("%s:\n%s", "projects", pformat(routes))

    return routes
Exemple #2
0
def setup_publications(app: web.Application):

    # routes
    specs = app[APP_OPENAPI_SPECS_KEY]
    routes = map_handlers_with_operations(
        get_handlers_from_namespace(publication_handlers),
        filter(lambda o: "publication" in o[3], iter_path_operations(specs)),
        strict=True,
    )
    app.router.add_routes(routes)
Exemple #3
0
def setup_tags(app: web.Application):
    assert app[APP_SETTINGS_KEY].WEBSERVER_TAGS  # nosec
    # routes
    specs = app[APP_OPENAPI_SPECS_KEY]
    routes = map_handlers_with_operations(
        get_handlers_from_namespace(tags_handlers),
        filter(lambda o: "tag" in o[3], iter_path_operations(specs)),
        strict=True,
    )
    app.router.add_routes(routes)
Exemple #4
0
def setup_users(app: web.Application):

    # routes related with users
    specs = app[APP_OPENAPI_SPECS_KEY]
    routes = map_handlers_with_operations(
        get_handlers_from_namespace(users_handlers),
        filter(lambda o: "me" in o[1].split("/"), iter_path_operations(specs)),
        strict=True,
    )
    app.router.add_routes(routes)
Exemple #5
0
def setup_groups(app: web.Application):

    # prepares scicrunch api
    setup_scicrunch_submodule(app)

    # routes
    specs = app[APP_OPENAPI_SPECS_KEY]
    routes = map_handlers_with_operations(
        get_handlers_from_namespace(groups_handlers),
        filter(lambda o: "groups" in o[1].split("/"), iter_path_operations(specs)),
        strict=True,
    )
    app.router.add_routes(routes)
def setup_publications(app: web.Application):
    assert app[APP_SETTINGS_KEY].WEBSERVER_PUBLICATIONS  # nosec

    setup_email(app)

    # routes
    specs = app[APP_OPENAPI_SPECS_KEY]
    routes = map_handlers_with_operations(
        get_handlers_from_namespace(publication_handlers),
        filter(lambda o: "publication" in o[3], iter_path_operations(specs)),
        strict=True,
    )
    app.router.add_routes(routes)
Exemple #7
0
def setup_groups(app: web.Application):

    assert app[APP_SETTINGS_KEY].WEBSERVER_GROUPS  # nosec

    # routes
    specs = app[APP_OPENAPI_SPECS_KEY]
    routes = map_handlers_with_operations(
        get_handlers_from_namespace(groups_handlers),
        filter(lambda o: "groups" in o[1].split("/"),
               iter_path_operations(specs)),
        strict=True,
    )
    app.router.add_routes(routes)
Exemple #8
0
def test_filtered_routing(specs):
    handlers = Handlers()
    found = get_handlers_from_namespace(handlers)

    hdl_sel = {name: hdl for name, hdl in found.items() if "i" in name}
    opr_iter = ((mth, url, opname, _tags)
                for mth, url, opname, _tags in iter_path_operations(specs)
                if "i" in opname)

    routes = map_handlers_with_operations(hdl_sel, opr_iter, strict=True)

    for rdef in routes:
        assert rdef.method == "GET"
        assert rdef.handler in hdl_sel.values()