コード例 #1
0
def test_query_get_result_invalid_format():
    """
    Test that get_result raises an error for format other than 'pandas' or 'geojson'.
    """
    query = APIQuery(connection="DUMMY_CONNECTION",
                     parameters={"query_kind": "dummy_query"})
    with pytest.raises(ValueError):
        query.get_result(format="INVALID_FORMAT")
コード例 #2
0
def test_query_get_result_runs(monkeypatch):
    """
    Test that get_result runs the query if it's not already running.
    """
    get_result_mock = Mock(return_value="DUMMY_RESULT")
    monkeypatch.setattr(f"flowclient.api_query.get_result_by_query_id", get_result_mock)
    connection_mock = Mock()
    query_spec = {"query_kind": "dummy_query"}
    connection_mock.post_json.return_value = Mock(
        status_code=202, headers={"Location": "DUMMY_LOCATION/DUMMY_ID"}
    )
    query = APIQuery(connection=connection_mock, parameters=query_spec)
    query.get_result()
    connection_mock.post_json.assert_called_once_with(route="run", data=query_spec)
コード例 #3
0
def test_query_get_result_pandas(monkeypatch, format, function):
    get_result_mock = Mock(return_value="DUMMY_RESULT")
    monkeypatch.setattr(f"flowclient.api_query.{function}", get_result_mock)
    connection_mock = Mock()
    connection_mock.post_json.return_value = Mock(
        status_code=202, headers={"Location": "DUMMY_LOCATION/DUMMY_ID"})
    query = APIQuery(connection=connection_mock,
                     parameters={"query_kind": "dummy_query"})
    query.run()
    assert "DUMMY_RESULT" == query.get_result(format=format, poll_interval=2)
    get_result_mock.assert_called_once_with(
        connection=connection_mock,
        disable_progress=None,
        query_id="DUMMY_ID",
        poll_interval=2,
    )