Exemplo n.º 1
0
def access_demo_app(dash_threaded, app_name):
    """Mimic a user click on the app link from the gallery."""
    driver = dash_threaded.driver
    dash_bio_index = import_app('index')
    dash_threaded(dash_bio_index)
    link = wait_for_element_by_id(driver, 'app-link-id-{}'.format(app_name))
    link.click()
Exemplo n.º 2
0
def test_install(dash_threaded):

    # Add the generated project to the path so it can be loaded from usage.py
    # It lies somewhere in a temp directory created by pytest-cookies
    sys.path.insert(0, '..')

    # Test that `usage.py` works after building the default component.
    dash_threaded(import_app('app'))
Exemplo n.º 3
0
def test_render_component(dash_threaded):
    # Start a dash app contained in `usage.py`
    # dash_threaded is a fixture by pytest-dash
    # It will load a py file containing a Dash instance named `app`
    # and start it in a thread.
    driver = dash_threaded.driver
    app = import_app('usage')
    dash_threaded(app)
Exemplo n.º 4
0
def test_imported_app(dash_threaded):
    app = import_app('test_apps.simple_app')
    dash_threaded(app)

    driver = dash_threaded.driver

    value_input = driver.find_element_by_id('value')
    value_input.clear()
    value_input.send_keys('Hello imported dash')

    wait_for_text_to_equal(driver, '#out', 'Hello imported dash')
Exemplo n.º 5
0
def test_start(dash_threaded):
    """Launch the app.

    `dash_threaded` is a fixture by `pytest-dash`.
    It will load a .py file containing a Dash instance
    and start it in a thread.
    """

    app = import_app('index')
    assert 'gallery', 'bioinformatics' in str(app.layout)

    # Test that `index.py` (the main gallery) works
    dash_threaded(app)
Exemplo n.º 6
0
def test_application(dash_threaded):

    driver = dash_threaded.driver
    app = import_app('webApp')

    counts = {'clicks': 0}

    dash_threaded(app)

    btn = wait_for.wait_for_element_by_css_selector(driver, '#date-picker')
    btn.click()

    wait_for.wait_for_text_to_equal(driver, '#out', '')
Exemplo n.º 7
0
def test_render_component(dash_threaded):
    # Start a dash app contained in `usage.py`
    # dash_threaded is a fixture by pytest-dash
    # It will load a py file containing a Dash instance named `app`
    # and start it in a thread.
    driver = dash_threaded.driver
    app = import_app('usage')
    dash_threaded(app)

    # Get the generated component input with selenium
    # The html input will be a children of the #input dash component
    my_component = wait_for_element_by_css_selector(driver, '#input > input')

    assert 'my-value' == my_component.get_attribute('value')

    # Clear the input
    my_component.clear()

    # Send keys to the custom input.
    my_component.send_keys('Hello dash')

    # Wait for the text to equal, if after the timeout (default 10 seconds)
    # the text is not equal it will fail the test.
    wait_for_text_to_equal(driver, '#output', 'You have entered Hello dash')
Exemplo n.º 8
0
def test_install(cookies, dash_threaded):
    results = cookies.bake(extra_context={
        'project_name': 'Test Component',
        'author_name': 'test',
        'author_email': 'test',
    })

    # Add the generated project to the path so it can be loaded from usage.py
    # It lies somewhere in a temp directory created by pytest-cookies
    sys.path.insert(0, str(results.project))

    selenium = dash_threaded.driver
    # Test that `usage.py` works after building the default component.
    dash_threaded(import_app('usage'))

    input_component = wait_for_element_by_css_selector(
        selenium,
        '#input > input'
    )
    input_component.clear()
    input_component.send_keys('Hello dash component')

    wait_for_text_to_equal(
        selenium,
        '#output',
        'You have entered Hello dash component'
    )

    node_modules = str(results.project.join('node_modules'))

    if sys.platform == 'win32':
        # Fix delete long names on windows.
        # pytest-cookies have trouble deleting some file generated by webpack.
        node_modules = '\\\\?\\' + node_modules

    shutil.rmtree(node_modules)
Exemplo n.º 9
0
def test_invalid_start_raises_threaded(dash_threaded):

    # Start the server without setting the layout.
    with pytest.raises(DashAppLoadingError):
        dash_threaded(import_app('test_apps.no_layout_app'), start_timeout=1)
Exemplo n.º 10
0
def test_no_app_found():
    with pytest.raises(NoAppFoundError):
        import_app('test_apps.invalid_app')
Exemplo n.º 11
0
def test_different_application_name_imported(dash_threaded):
    app = import_app(
        'test_apps.different_app_name', application_name='different'
    )
    dash_threaded(app)
    wait_for_text_to_equal(dash_threaded.driver, '#body', 'Different')