コード例 #1
0
def test_initialized_table_plotter(dash_duo: DashComposite) -> None:

    app = dash.Dash(__name__)
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    app.config.suppress_callback_exceptions = True
    CACHE.init_app(app.server)
    webviz_settings = WebvizSettings({}, default_theme)
    csv_file = Path("./tests/data/example_data.csv")
    plot_options = dict(
        x="Well",
        y="Initial reservoir pressure (bar)",
        size="Average permeability (D)",
        facet_col="Segment",
    )

    page = _table_plotter.TablePlotter(app,
                                       webviz_settings,
                                       csv_file,
                                       lock=True,
                                       plot_options=plot_options)
    app.layout = page.layout
    dash_duo.start_server(app)

    # Wait for the app to render(there is probably a better way...)

    # Checking that plot options are defined
    assert page.plot_options == plot_options
    assert page.lock

    # Checking that the selectors are hidden
    selector_row = dash_duo.find_element("#" + page.uuid("selector-row"))
    assert "display: none;" in selector_row.get_attribute("style")
コード例 #2
0
def test_table_plotter(dash_duo: DashComposite) -> None:

    app = dash.Dash(__name__)
    app.config.suppress_callback_exceptions = True
    CACHE.init_app(app.server)
    webviz_settings = WebvizSettings({}, default_theme)
    csv_file = Path("./tests/data/example_data.csv")
    page = _table_plotter.TablePlotter(app, webviz_settings, csv_file)
    app.layout = page.layout
    dash_duo.start_server(app)

    # Wait for the app to render(there is probably a better way...)
    time.sleep(5)

    # Checking that no plot options are defined
    assert page.plot_options == {}
    # Check that filter is not active
    assert not page.use_filter

    # Checking that the correct plot type is initialized
    plot_dd = dash_duo.find_element("#" + page.uuid("plottype"))
    assert plot_dd.text == "scatter"

    # Checking that only the relevant options are shown
    for plot_option in page.plot_args.keys():
        plot_option_dd = dash_duo.find_element("#" +
                                               page.uuid(f"div-{plot_option}"))
        if plot_option not in page.plots["scatter"]:
            assert plot_option_dd.get_attribute("style") == "display: none;"

    # Checking that options are initialized correctly
    for option in ["x", "y"]:
        plot_option_dd = dash_duo.find_element("#" +
                                               page.uuid(f"dropdown-{option}"))
        assert plot_option_dd.text == "Well"
コード例 #3
0
ファイル: plugin.py プロジェクト: Srijan1998/dash
def dash_duo(request, dash_thread_server):
    with DashComposite(
            dash_thread_server,
            browser=request.config.getoption("webdriver"),
            headless=request.config.getoption("headless"),
            options=request.config.hook.pytest_setup_options(),
    ) as dc:
        yield dc
コード例 #4
0
ファイル: plugin.py プロジェクト: FathiahHusna/MySuspicious
def dash_duo(request, dash_thread_server, tmpdir):
    with DashComposite(
        dash_thread_server,
        browser=request.config.getoption("webdriver"),
        headless=request.config.getoption("headless"),
        options=request.config.hook.pytest_setup_options(),
        download_path=tmpdir.mkdir('download').strpath
    ) as dc:
        yield dc
コード例 #5
0
def test_full_example(testdata_folder: Path, dash_duo: DashComposite,
                      tmp_path: Path) -> None:

    # https://github.com/plotly/dash/issues/1164:
    # We are accessing a private member here which seems to be necessary due to the
    # aforementioned issue. Ignore the respective pylint warning.
    # pylint: disable=protected-access
    dash_duo._wd_wait = WebDriverWait(
        dash_duo.driver,
        timeout=10,
        ignored_exceptions=(NoSuchElementException,
                            StaleElementReferenceException),
    )
    # pylint: enable=protected-access

    # Build a portable webviz from config file
    appdir = tmp_path / "app"
    subprocess.call(  # nosec
        ["webviz", "build", "webviz-raw-data.yml", "--portable", appdir],
        cwd=testdata_folder / "webviz_examples",
    )
    # Remove Talisman
    file_name = appdir / "webviz_app.py"
    with open(file_name, "r") as file:
        lines = file.readlines()
    with open(file_name, "w") as file:
        for line in lines:
            if not line.strip("\n").startswith("Talisman"):
                file.write(line)
    # Import generated app
    sys.path.append(str(appdir))

    # webviz_app was just created, temporarily ignore the import-outside-toplevel warning
    # and the import-error.
    # pylint: disable=import-outside-toplevel
    # pylint: disable=import-error
    from webviz_app import app

    # pylint: enable=import-outside-toplevel
    # pylint: enable=import-error

    # Start and test app
    dash_duo.start_server(app)
    for page in [
            "inplacevolumesonebyone",
            "reservoirsimulationtimeseriesonebyone",
            "inplacevolumes",
            "parameterdistribution",
            "parametercorrelation",
            "reservoirsimulationtimeseries",
    ]:
        dash_duo.wait_for_element(f"#{page}").click()
        logs = [
            log for log in dash_duo.get_logs() if
            "TypeError: Cannot read property 'hardwareConcurrency' of undefined"
            not in log["message"]
        ]

        if logs != []:
            raise AssertionError(page, logs)
コード例 #6
0
def test_param_injection(dash_duo: DashComposite):
    """Test that URL parameters get injected into the body of dash callback requests."""
    dashboard_id = "test-db"
    param_one = "foo"
    param_two = "bar"
    callback_complete = "done"
    test_input = "test-input"
    test_output = "test-output"

    dashboard = create_new_dashboard(dashboard_id)

    dashboard.layout = html.Div(
        [html.Div(id=test_input),
         html.Div(id=test_output)])

    @dashboard.callback(Output(test_output, "children"),
                        Input(test_input, "children"))
    def assert_url_params(_):
        # (see the URL we navigate to below)
        assert request.json["param_one"] == param_one
        assert request.json["param_two"] == param_two
        return callback_complete

    dash_duo.server(dashboard)
    dash_duo.wait_for_page(
        f"{dash_duo.server.url}/dashboards/{dashboard_id}?param_one={param_one}&param_two={param_two}"
    )

    dash_duo.wait_for_text_to_equal(f"#{test_output}", callback_complete)
コード例 #7
0
def dash_duo(request, dash_thread_server, tmpdir):
    with DashComposite(
            dash_thread_server,
            browser=request.config.getoption("webdriver"),
            remote=request.config.getoption("remote"),
            remote_url=request.config.getoption("remote_url"),
            headless=request.config.getoption("headless"),
            options=request.config.hook.pytest_setup_options(),
            download_path=tmpdir.mkdir("download").strpath,
            percy_assets_root=request.config.getoption("percy_assets"),
            percy_finalize=request.config.getoption("nopercyfinalize"),
    ) as dc:
        yield dc
コード例 #8
0
def dash_duo(request, dash_thread_server):
    with DashComposite(dash_thread_server,
                       request.config.getoption("webdriver")) as dc:
        yield dc
コード例 #9
0
def test_shipments_dashboard(cidc_api, clean_db, monkeypatch,
                             dash_duo: DashComposite):
    """
    Check that the shipments dashboard behaves as expected.
    """
    user, _, _ = setup_data(cidc_api, clean_db)

    for role in ROLES:
        make_role(user.id, role, cidc_api)
        mock_current_user(user, monkeypatch)

        dash_duo.server(shipments_dashboard)
        dash_duo.wait_for_page(
            f"{dash_duo.server.url}/dashboards/upload_jobs/")

        if CIDCRole(role) == CIDCRole.ADMIN:
            # open trial dropdown
            dash_duo.click_at_coord_fractions(f"#{TRIAL_DROPDOWN}", 0.1, 0.1)
            dash_duo.wait_for_contains_text(f"#{TRIAL_DROPDOWN}", trial_id)
            # select the first trial
            trial_select = dash_duo.find_elements(
                ".VirtualizedSelectOption")[0]
            dash_duo.click_at_coord_fractions(trial_select, 0.1, 0.1)
            # click off dropdown to close it
            dash_duo.click_at_coord_fractions(f"#{SHIPMENTS_TABLE_ID}", 0.1,
                                              0.1)
            # ensure the shipments table loads
            dash_duo.wait_for_contains_text(f"#{SHIPMENTS_TABLE_ID}",
                                            manifest_id)
            # open manifest dropdown
            dash_duo.click_at_coord_fractions(f"#{MANIFEST_DROPDOWN}", 0.1,
                                              0.1)
            dash_duo.wait_for_contains_text(f"#{TRIAL_DROPDOWN}", trial_id)
            # select the first manifest
            manifest = dash_duo.find_elements(".VirtualizedSelectOption")[0]
            dash_duo.click_at_coord_fractions(manifest, 0.1, 0.1)
            # ensure the samples table loads
            dash_duo.wait_for_contains_text(f"#{SAMPLES_TABLE_ID}",
                                            "CTTTPP1SS.01")
        else:
            dash_duo._wait_for_callbacks()
            assert any([
                "401 (UNAUTHORIZED)" in log["message"]
                for log in dash_duo.get_logs()
            ])