Exemple #1
0
def BokehApplication(applications, server, prefix="/", template_variables={}):
    prefix = prefix or ""
    prefix = "/" + prefix.strip("/")
    if not prefix.endswith("/"):
        prefix = prefix + "/"

    extra = toolz.merge({"prefix": prefix}, template_variables)

    apps = {
        k: functools.partial(v, server, extra)
        for k, v in applications.items()
    }
    apps = {k: Application(FunctionHandler(v)) for k, v in apps.items()}
    kwargs = dask.config.get(
        "distributed.scheduler.dashboard.bokeh-application").copy()
    extra_websocket_origins = create_hosts_allowlist(
        kwargs.pop("allow_websocket_origin"), server.http_server.port)

    application = BokehTornado(
        apps,
        prefix=prefix,
        use_index=False,
        extra_websocket_origins=extra_websocket_origins,
        **kwargs,
    )
    return application
Exemple #2
0
def test_create_hosts_allowlist_bad_host_raises() -> None:
    with pytest.raises(ValueError):
        util.create_hosts_allowlist([""], 1000)

    with pytest.raises(ValueError):
        util.create_hosts_allowlist(["a:b:c"], 1000)

    with pytest.raises(ValueError):
        util.create_hosts_allowlist([":80"], 1000)
Exemple #3
0
def test_create_hosts_allowlist_host_without_port_use_port_80() -> None:
    hosts = util.create_hosts_allowlist(["foo"], 1000)
    assert hosts == ["foo:80"]

    hosts = util.create_hosts_allowlist(["foo", "bar"], 1000)
    assert hosts == ["foo:80", "bar:80"]
Exemple #4
0
def test_create_hosts_allowlist_host_value_with_port_use_port() -> None:
    hosts = util.create_hosts_allowlist(["foo:1000"], 1000)
    assert hosts == ["foo:1000"]

    hosts = util.create_hosts_allowlist(["foo:1000", "bar:2100"], 1000)
    assert hosts == ["foo:1000", "bar:2100"]
Exemple #5
0
def test_create_hosts_allowlist_no_host() -> None:
    hosts = util.create_hosts_allowlist(None, 1000)
    assert hosts == ["localhost:1000"]

    hosts = util.create_hosts_allowlist([], 1000)
    assert hosts == ["localhost:1000"]
Exemple #6
0
def test_create_hosts_allowlist_host_non_int_port_raises() -> None:
    with pytest.raises(ValueError):
        util.create_hosts_allowlist(["foo:xyz"], 1000)