Exemplo n.º 1
0
def test_system_queries_based_on_date_and_location_and_crime_type(dash_duo):
    app = Dash(__name__)
    app.layout = simple_app_layout()

    # instantiates a database
    database = Database.Connection()

    # Update Function based on date-picker,location dropdown, and type of crime
    @app.callback([
        Output('output-container-date-picker-range', 'children'),
        Output("output-1", "children"),
        Output("output-2", "children")
    ], [
        Input('my-date-picker-range', 'start_date'),
        Input('my-date-picker-range', 'end_date'),
        Input("crime-dropdown", "value"),
        Input("location-dropdown", "value")
    ])
    def update_graph(start_date, end_date, selectedCrime, selectedLocation):
        # DO STUFF IN THE APP
        # only queries with when dates are selected
        if start_date and end_date:
            # false call to the pull function
            cm.database_pull(start_date, end_date, selectedCrime,
                             selectedLocation, database)

        string_prefix = 'You have selected: '
        if start_date is not None:
            start_date = dt.strptime(start_date.split(' ')[0], '%Y-%m-%d')
            start_date_string = start_date.strftime('%B %d, %Y')
            string_prefix = string_prefix + 'Start Date: ' + start_date_string + ' | '
        if end_date is not None:
            end_date = dt.strptime(end_date.split(' ')[0], '%Y-%m-%d')
            end_date_string = end_date.strftime('%B %d, %Y')
            string_prefix = string_prefix + 'End Date: ' + end_date_string
        if len(string_prefix) == len('You have selected: '):
            return 'Select a date to see it displayed here', selectedCrime, selectedLocation
        else:
            return string_prefix, selectedCrime, selectedLocation

    dash_duo.start_server(app)
    date_picker = dash_duo.driver.find_element_by_xpath(
        "// *[ @ id ='my-date-picker-range']/div")
    start_input = date_picker.find_element_by_xpath(
        "//*[@id='my-date-picker-range']/div/div/div/div[1]/input")
    start_input.send_keys("09/11/2019")
    end_input = date_picker.find_element_by_xpath(
        "//*[@id='my-date-picker-range']/div/div/div/div[3]/input")
    end_input.send_keys("10/11/2019")

    dash_duo.wait_for_text_to_equal(
        "#output-container-date-picker-range",
        "You have selected: Start Date: September 11, 2019 | End Date: October 11, 2019",
        timeout=5.0)
    dash_duo.select_dcc_dropdown("#location-dropdown", index=0)
    dash_duo.select_dcc_dropdown("#crime-dropdown", index=0)

    assert database.crime_date_queried
    assert database.crime_location_queried
    assert database.crime_type_queried
Exemplo n.º 2
0
def test_system_does_not_update_upon_start_up(dash_duo):
    app = Dash(__name__)
    app.layout = simple_app_layout()

    # sets the initial values to check if system changes them
    start = None
    end = None
    crime = None
    location = None

    @app.callback([
        Output('output-container-date-picker-range', 'children'),
        Output("output-1", "children"),
        Output("output-2", "children")
    ], [
        Input('my-date-picker-range', 'start_date'),
        Input('my-date-picker-range', 'end_date'),
        Input("crime-dropdown", "value"),
        Input("location-dropdown", "value")
    ])
    def update_graph(start_date, end_date, selectedCrime, selectedLocation):
        # DO STUFF IN THE APP
        nonlocal start, end, crime, location
        start = start_date
        end = end_date
        crime = selectedCrime
        location = selectedLocation

        return start_date, selectedCrime, selectedLocation

    assert not crime
    assert not start
    assert not end
    assert not location
Exemplo n.º 3
0
def test_system_queries_based_on_date_only(dash_duo):
    app = Dash(__name__)
    app.layout = simple_app_layout()

    database = Database.Connection()

    @app.callback([
        Output('output-container-date-picker-range', 'children'),
        Output("output-1", "children"),
        Output("output-2", "children")
    ], [
        Input('my-date-picker-range', 'start_date'),
        Input('my-date-picker-range', 'end_date'),
        Input("crime-dropdown", "value"),
        Input("location-dropdown", "value")
    ])
    def update_graph(start_date, end_date, selectedCrime, selectedLocation):
        # DO STUFF IN THE APP
        # only queries with when dates are selected
        if start_date and end_date:
            # false call to the pull function
            cm.database_pull(start_date, end_date, selectedCrime,
                             selectedLocation, database)

        sentance = str(start_date) + str(end_date)
        return sentance, selectedCrime, selectedLocation

    # Select an arbitrary date range (Code is tested in unit tests)
    dash_duo.start_server(app)
    date_picker = dash_duo.driver.find_element_by_xpath(
        "// *[ @ id ='my-date-picker-range']/div")
    start_input = date_picker.find_element_by_xpath(
        "//*[@id='my-date-picker-range']/div/div/div/div[1]/input")
    start_input.send_keys("09/11/2019")
    end_input = date_picker.find_element_by_xpath(
        "//*[@id='my-date-picker-range']/div/div/div/div[3]/input")
    end_input.send_keys("10/11/2019")

    assert database.crime_date_queried
    assert not database.crime_location_queried
    assert not database.crime_type_queried