Esempio n. 1
0
def test_joined_spatial_aggregate(access_token_builder, flowapi_url):
    """TODO: Once there are metrics that can be used, replace this test"""
    con = flowclient.Connection(
        url=flowapi_url,
        token=access_token_builder(
            {
                "daily_location": {
                    "permissions": {"run": True, "poll": True, "get_result": True},
                    "spatial_aggregation": ["admin3"],
                },
                "dummy_query": {
                    "permissions": {"run": True, "poll": True, "get_result": True},
                    "spatial_aggregation": ["admin3"],
                },
            }
        ),
    )
    with pytest.raises(
        flowclient.client.FlowclientConnectionError, match="status 'errored'"
    ):
        result = flowclient.get_result(
            connection=con,
            query=flowclient.joined_spatial_aggregate(
                locations=flowclient.daily_location(
                    date="2016-01-01", aggregation_unit="admin3", method="last"
                ),
                metric={"query_kind": "dummy_query", "dummy_param": "dummy_value"},
            ),
        )
Esempio n. 2
0
def test_get_geography(access_token_builder, flowapi_url):
    """
    Test that queries can be run, and return a GeoJSON dict.
    """
    con = flowclient.Connection(
        url=flowapi_url,
        token=access_token_builder(
            {
                "geography": {
                    "permissions": permissions_types,
                    "spatial_aggregation": aggregation_types,
                }
            }
        ),
    )
    result_geojson = flowclient.get_geography(connection=con, aggregation_unit="admin3")
    assert "FeatureCollection" == result_geojson["type"]
    assert 0 < len(result_geojson["features"])
    feature0 = result_geojson["features"][0]
    assert "Feature" == feature0["type"]
    assert "admin3name" in feature0["properties"]
    assert "admin3pcod" in feature0["properties"]
    assert "MultiPolygon" == feature0["geometry"]["type"]
    assert list == type(feature0["geometry"]["coordinates"])
    assert 0 < len(feature0["geometry"]["coordinates"])
Esempio n. 3
0
def test_run_query(query_kind, params, universal_access_token, flowapi_url):
    """
    Test that queries can be run, and return a QueryResult object.
    """
    query_spec = getattr(flowclient, query_kind)(**params)
    con = flowclient.Connection(url=flowapi_url, token=universal_access_token)

    get_result(connection=con, query=query_spec)
Esempio n. 4
0
def test_fail_query_incorrect_parameters(query_kind, params,
                                         universal_access_token, flowapi_url):
    """
    Test that queries fail with incorrect parameters.
    """
    query_spec = getattr(flowclient, query_kind)(**params)
    con = flowclient.Connection(url=flowapi_url, token=universal_access_token)
    with pytest.raises(flowclient.client.FlowclientConnectionError,
                       match="Must be one of:"):
        result_dataframe = get_result(connection=con, query=query_spec)
Esempio n. 5
0
def test_get_available_dates(event_types, expected_result,
                             access_token_builder, flowapi_url):
    """
    Test that queries can be run, and return the expected JSON result.
    """
    con = flowclient.Connection(
        url=flowapi_url,
        token=access_token_builder(["get_result&available_dates"]),
    )
    result = flowclient.get_available_dates(connection=con,
                                            event_types=event_types)
    assert expected_result == result
Esempio n. 6
0
def test_run_query(query_kind, params, access_token_builder, api_host):
    """Test that queries can be run, and return a QueryResult object."""
    con = flowclient.Connection(
        api_host,
        access_token_builder({
            query_kind: {
                "permissions": permissions_types,
                "spatial_aggregation": aggregation_types,
            }
        }),
    )
    result_dataframe = get_result(con,
                                  getattr(flowclient, query_kind)(**params))
    assert 0 < len(result_dataframe)