def test_all_data(server_with_data):
    resp = server_with_data.server.client.get(flask.url_for(
        'graph.all_data',
        metric_name=PythonImportCount.__name__,
    ))

    # Should redirect to a show url
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=PythonImportCount.__name__),
        # Tested more explicitly below
        mock.ANY,
    )
    # This part is a bit racey due to how the commits were made.
    # Instead of opting for more-exact timing here, I decided to unit test
    # the underlying function and give a fuzzy check here.  The important part
    # about this endpoint is it redirects to a show url and doesn't start at 0
    timestamp = server_with_data.cloneable_with_commits.commits[-1].date
    parsed_qs = urllib_parse.parse_qs(
        urllib_parse.urlparse(resp.response.location).query,
    )
    assert int(parsed_qs['start'][0]) > 0
    assert int(parsed_qs['start'][0]) <= timestamp
Example #2
0
def test_all_data(server_with_data):
    resp = server_with_data.server.client.get(
        flask.url_for(
            'graph.all_data',
            metric_name=PythonImportCount.__name__,
        ))

    # Should redirect to a show url
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=PythonImportCount.__name__),
        # Tested more explicitly below
        mock.ANY,
    )
    # This part is a bit racey due to how the commits were made.
    # Instead of opting for more-exact timing here, I decided to unit test
    # the underlying function and give a fuzzy check here.  The important part
    # about this endpoint is it redirects to a show url and doesn't start at 0
    timestamp = server_with_data.cloneable_with_commits.commits[-1].date
    parsed_qs = urllib_parse.parse_qs(
        urllib_parse.urlparse(resp.response.location).query, )
    assert int(parsed_qs['start'][0]) > 0
    assert int(parsed_qs['start'][0]) <= timestamp
def assert_redirect(response, path, query, redirect_status_code=302):
    assert response.response.status_code == redirect_status_code
    parsed_redirect = urllib_parse.urlparse(response.response.location)
    assert parsed_redirect.path == path
    parsed_query_string = urllib_parse.parse_qs(parsed_redirect.query)
    assert parsed_query_string == query