Example #1
0
def template_test_python_component_prop(dash_threaded,
                                        app_name,
                                        assert_callback,
                                        update_component_callback,
                                        prop_name,
                                        prop_value,
                                        prop_type=None,
                                        component_base=COMPONENT_PYTHON_BASE,
                                        **kwargs):
    template_test_component(dash_threaded,
                            app_name,
                            assert_callback,
                            update_component_callback,
                            prop_name,
                            prop_value,
                            prop_type=prop_type,
                            component_base=component_base,
                            **kwargs)

    driver = dash_threaded.driver

    btn = wait_for_element_by_css_selector(driver,
                                           '#test-{}-btn'.format(app_name))
    btn.click()
    wait_for_text_to_equal(driver,
                           '#test-{}-assert-value-div'.format(app_name),
                           'PASSED')
Example #2
0
def test_dash_threaded(dash_threaded):
    app = dash.Dash(__name__)

    app.layout = html.Div([
        html.Button('click me', id='clicker'),
        html.Div(id='output')
    ])

    call_count = Queue()

    @app.callback(Output('output', 'children'), [Input('clicker', 'n_clicks')])
    def on_click(n_clicks):
        call_count.put(1)
        if n_clicks is None:
            raise PreventUpdate

        return n_clicks

    dash_threaded(app, port=8090)
    assert 'http://localhost:8090' in dash_threaded.driver.current_url

    clicker = wait_for_element_by_css_selector(
        dash_threaded.driver, '#clicker'
    )

    for i in range(6):
        clicker.click()
        wait_for_text_to_equal(dash_threaded.driver, '#output', str(i + 1))

    assert call_count.qsize() == 7
Example #3
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')
Example #4
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', '')
Example #5
0
def test_suggestions_input(dash_threaded):
    from test_apps.suggestions_input import app
    selenium = dash_threaded.driver
    dash_threaded(app)

    suggestion_input = wait_for_element_by_css_selector(
        selenium, '#suggestions')

    # Tests all suggestion types.
    suggestion_input.send_keys('$Term\t')
    wait_for_text_to_equal(selenium, '#suggestions-output', 'Terminator')

    # Backend/Callback powered suggestions
    # need a small delay for the suggestions to appear
    # without losing the focus on the component for the modal to stay up.
    # test might be flaky...
    clear_input(suggestion_input)
    time.sleep(1)
    suggestion_input.send_keys('@call')
    time.sleep(1)
    suggestion_input.send_keys('\t')
    wait_for_text_to_equal(selenium, '#suggestions-output', 'callback')
Example #6
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')
Example #7
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)
Example #8
0
def test_different_application_name_subprocess(dash_subprocess):
    dash_subprocess(
        'test_apps.different_app_name', application_name='different'
    )
    wait_for_text_to_equal(dash_subprocess.driver, '#body', 'Different')
Example #9
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')